Now we’re getting into the “real stuff” or rather IT-related stuff.
I am now attending a session with Scott Allen, who is a great guy by the way, on ASP.NET MVC. As readers of this blog know I love this framework already since it got me back on understanding web development again.
OK - since Scott is dropping god nuggets as he speak, I thought that I put it here as we go, in no particular order;
- When you create the “URL template” for routing you can specify anything you want. For example {controller}/{action}/{category}/{locale} would fill the category and local with anything passed to the URL or null if not set.
- Learn and use MVC Contrib
- Set the projectfile-setting MvcBuildViews to get compilation errors for errors in the views. This slows builds down so don’t use it when not needed.
- Test your routing with Fluent HTML Testing Routes
- Check out ActionFilters to be able to hook into the “events” of the action methods; OnActionExcecuting, OnActionExecuted etc.
- I got a big aha-moment when Scott described the Execute-method of IController-interface. Especially check out the RequestContext object sent to the Execute-method, that contains RouteData-dictionary. There you have your route-template values…
- I can’t believe that I’ve forgot about UpdateModel. It’s a good thing - but sending the strong type is better :)
- Build your own HTML helper methods for everything except the trivial HTML-generation. “If you ever have a if-statment in your view use a HTML helper” - was the exact quote.
- The web.config in the View-folder is just to get people not to try to pull down your views directly.
Thank you Scott for a great overview. I link the slides here when available.