Tuesday, May 27, 2008

ASP.NET MVC Preview 3 released today

For all of you MVC fans out there, listen up: the third preview release of the ASP.NET MVC Framework has just dropped and is now available for download at the normal locations. This release comes about two months after the last "official" release (Preview 2 - released March 18th) and continues the iterative release trend Microsoft has adopted for the MVC project. Under this model, Microsoft is releasing bits for its new framework much earlier than it normally would and relying heavily on community feedback to guide the direction of the product. The approach has its pros and cons- we get to play with code earlier (pro) but lots of incorrect (a.k.a. outdated) information about the framework floods the internet (con). I'll reserve my judgment on this "experimental" product development approach 'til we see what the MVC team ultimately produces, but in the mean time, use caution when searching the interwebs for ASP.NET MVC help. It's likely already out of date.

Point in case, the new Preview 3 release makes a number of fundamental changes to the way ASP.NET MVC works. These changes are to be expected as the MVC team tweaks the Framework's API to "feel right," but if you've been dipping your toes in the MVC pool with Preview 2 be preparred to make some code changes. Among the key changes in this release:

  • Action methods in MVC Controllers no longer rely on the static RenderView() method to render a view. Instead, a more flexible ActionResult is now returned by action methods. There are 6 enumerated ActionResult types, easily enabling you to do everything from render HTML (ViewResult) to redirecting the users (RedirectResult). This change will affect Preview 2 apps.
  • The ViewData property of ViewPage no longer returns T. Instead, a new property has been added to the page's ViewDataDictionary to handle that task: Model. Call the Model property to access a strongly typed collection of data passed to the page.
  • Routing has changed a lot in in Preview 3. The most significant change is the way routes are defined in the Global.asax file. A new MapRoute extension method makes the process much simpler than Preview 2, significantly reducing the number of lines of code it takes to define routes. This is a welcome change, but it will also require you to update your Preview 2 apps.
For a complete overview of the changes in Preview 3, be sure to review the release notes (caution: Word link). You can also find an exhaustive post covering all of the changes in Preview 3 from the master of increbile blogging, ScottGu.

Many of these changes are going to make MVC more enjoyable to use. The new ActionResult, for instance, is going to dramatically simplify MVC unit testing by removing the previously painful mocking required to test views. We also get the impression from Scott's post that the MVC team is "starting to feel good" about the MVC URL routing and controller/action components, so we may start to see these APIs stabilize in future releases. Scott's also indicating that future MVC releases will focus more on delivering improved HTML Helpers and better Ajax integration, two areas that are very interesting to those of us that spend a lot of time in the UI. I guess we'll find out in another couple of months.

Until then, enjoy the new preview and let us know what you think. Is ASP.NET MVC something that you'd consider using instead of WebForms in your organization?