13 Apr 2008

Coder Journal’s MVC Toolkit

9 Comments Uncategorized

Today I decided to release a toolkit that I have been building over the past couple of months. Most of the code in the toolkit is related to MVC. Here is a list of the features:

ActionFilterAttribute’s

  • HttpPostOnlyAttribute
    Only allows POST to be made against the action.
  • CacheAttribute
    Sets the action’s response as cacheable.
  • CompressAttribute
    Compresses the action’s response using GZip or Deflate encoding.
  • ServiceAttribute
    Marks an action as able to provide the ViewData as JSON, XML, or JSONP.
  • ServiceOnlyAttribute
    Marks an action as only able to provide the ViewData as JSON, XML, or JSONP, that means no HTML.
  • ExceptionHandlerAttribute
    Handles any exceptions thrown from an action, and redirects it to another page, or another action.
  • CaptchaAttribute
    I did a whole post on providing a CAPTCHA for your MVC action.
  • AllowedHttpMethodsAttribute
    Only the HTTP methods entered in to this filter are allowed for your action. Available HTTP methods are OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, and CONNECT.

ViewEngines’s

  • ServiceViewEngine
    This view engine provides the serialization of the ViewData to JSON, XML, or JSONP. It is set when one of the following is requested from the ServiceAttribute above.

Route’s

Method Extensions

  • Redirect extends HttpResponse
    I have had a long standing discontent with the Redirect method of the ASP.NET. I have talked about good use of HTTP Status Codes before. There are at least 3 status codes that you want to consider before choosing a response status code of 302. Just to reiterate my post on the subject use 303 to redirect from a form POST, use 307 when you want to redirect to a page that is going to change with each request, use 301 if you want to permanently redirect one URL to another.I created the, Redirect, extension method on HttpResponse so that the status code could be set for the redirect.

View Source: Coder Journal MVC Toolkit Source
Download Binary: Coder Journal MVC Toolkit Binary

Update: I have updated one bug found.  Both links above contain the updated source and binaries.

Tags: , , ,
written by
Nick Berardi
subscribe
If you found this post valuable and would like to see more like it you can follow me.

9 Responses to “Coder Journal’s MVC Toolkit”

  1. Reply Jeffro says:

    Excellent! Thanks for posting this – I’ve followed your posts – having this in collected into a library is so useful!

  2. Reply Kenneth Auchenberg says:

    What about some credit to the creators of the code?

    Compress & Cache Attribute = http://weblogs.asp.net/rashid/archive/2008/03/28/asp-net-mvc-action-filter-caching-and-compression.aspx

    Your toolkit is quite nice, but at least you could provide a comment that tells where you got the code from.

  3. Reply Nick Berardi says:

    Kenneth,

    Thanks for alerting me to that. I can’t remember where I picked up some of the code sometimes. I have updated the code with a link back to Kazi Manzur Rashid’s site.

    Nick

Leave a Reply