.net - What clever things have you done with an ASP.NET MVC Action method -


ASP.NET MVC controller action methods are mainly used to handle 'business' tasks but it can be used for a lot more.

I thought it would be fun to see which creative, useful things have created works for people, which can be practical or useful for others.

Here's my contribution:

Javascript file concensator - to

  [output cache (duration = 5 * 60 , VarietyPaperM = ""]] / / Use "None" here * Render JavaScript () {StringBinder JS = New StringBuilder (); StringWrite SW = New Stringer (JS); // Load all my javascript files js.AppendLine (file. Read all tags (Request MapPath ("~ / scripts / jquery.hoverIntent.minified.js"))); Js.AppendLine (File.ReadAllText (Request.MapPath ("~ / script / jquery.corner.js"))); Js.AppendLine (File.ReadAllText (Request.MapPath ("~ / script / rollingrazor.js"))); Return new content (refund) {content = js.ToString (), content type = "app / x-javascript"}; }  

One way map for this:

  // JavaScript routes. MapRoute ("js-route", "dynamic / js", new controller = "app", action = "render javascript"});  

See this from your master page:

  & lt; Script type = "text / javascript" src = "/ dynamic / js" & gt; & Lt; / Script & gt;  

WARNING I have set a cache for output, so if you are changing your JS and refreshing the page, then you can disable the cache!

I should come back and know how to make it alive.

* You should not use verbarem = "none" because this is due to send different headers, which If you really have to change your JS content, your users have to wait 5 minutes for it!

Is there a clever count?

  Public Class Permanent Redirect Result: Actionersult {Public String URL {Received; Set; } Public Permanent Redirect Result (String Url) {if (string .asnlorquite (url)) (new url option ("url is empty or empty", "url");} This.Url = url;} Public override zero ExecuteResult Controller Context Reference) {if (context == null) {New argument NullException ("Reference");} Context.HttpContext.Response.StatusCode = 301; Reference.HttpContext.Response.RedirectLocation = Url;}}  

Comments