Notes on Asp.Net MVC
Here are some notes about Asp.Net MVC:
Asp.Net MVC is modelled around Model2 (Struts-like) framework based on the original MVC. The controller processes the HTTP requests, finds a View and passes the ViewModel to the View. The View updates itself with the ViewModel.
In Webforms, the Page class is the HTTP Handler. MVC requests are handled by MVC Handler. MVC Handler examines the URL to identify the right controller factory and the right controller. The controller has an execute method that does most of the processing. Internally the controller uses ActionInvoker to identify the action and invoke the action. Action selectors are attributes that can help identify the right action to select for a request. Action filters operate before and after the method call and does things like authorization, exception handling, etc. The result of the action method call is wrapped into an ActionResult object. The ActionResult has an ExecuteResult method that provides the final response to the browser. ActionResult can be ViewResult, JSONResult, FileResult, EmptyResult etc. It is upto the View engine to process the ActionResult to produce meaningful HTML / Javascript to the browser.
All aspects of MVC is customizable - ControllerFactory, Controller, ActionInvoker, ActionFilter, ActionSelector, ViewEngine, ViewResult, ModelBinder.
The default View engine in MVC is the WebformsViewEngine. This means that master pages, content pages, user controls, themes, will work well in MVC. Because MVC does not have a page postback lifecycle, events on controls will not be triggered. Server controls are generally not recommended in MVC. Server controls generate ViewState which is of no use in the MVC world. MVC uses Helper classes to generate HTML. Helpers exist for both HTML, AJAX. However, I would recommend using JQuery extensively in MVC apps instead of the helper classes.
Till Microsoft supports MVC with a MVCViewEngine with a set of server controls suited for MVC, the adoption of MVC will be slow. SparkViewEngine has a set of HTML tags that can fill this void, for the time being. Maybe MVC 3 will have more UI features like Intellisense for controllers, actions etc. R# (Resharp) is a third-party plug-in that provides similar features.
Update: Razor in MVC 3 seems to be what we need in a ViewEngine. Will be checking, if I can migrate this blog to use MVC with Razor.
Category : ASP.NET MVC


