The Model-View-Controller (MVC) concept has been around for quite awhile, but this is the first time Microsoft has provided robust support for it in the hugely popular ASP.NET web technology framework. Not designed to be a replacement for ASP.NET Web Forms, their MVC framework is simply an alternative approach that also enables test-driven development.
This first release candidate is expected to be the only release candidate, with the final, production build following close behind.
The ASP.NET MVC Framework
The MVC framework is both a design pattern and an architectural pattern. It was first seen in 1979 -- so it's not that new. It's been used in a number of programming languages for quite awhile now.
Basic MVC Pattern Diagram
The MVC pattern is designed to separate the user interface from the business logic of an application, resulting in easier testing of the application. The three components of this pattern are defined as follows:
- Model: Represents the state of an application, often mapping to a database table
- View: Displays the UI for the application
- Controller: Controls how the input into the UI is handled, manipulates the model and determines which UI to present to the user
You learn all you need to know about this pattern, including a number of tutorials and videos on the ASP.NET website.
ASP.NET MVC RC1
The first (and expected only) release candidate just came out and offers a number of new capabilities in addition to bug fixes. Five previews and one beta later, here are some of the new features for Visual Studio support included in the Release Candidate:
Visual Studio Tooling Improvements
- Add Controller Command: Easily create new controller classes
- Add View Command: Create new view templates to a controller action method (create empty views or generate/scaffold view templates based on the object passed). A number of built-in scaffold templates come with RC1: “Empty”, “List”, “Details”, “Edit” and “Create"
- Adding and Customizing Scaffold Templates: The scaffolding architecture is built on Visual Studio’s built-in T4 templating architecture, so you can customize/override any of the scaffolds that comes with RC1 or create additional scaffold templates. This can be done at either the machine or project level.
- Go To Controller / Go To View: Quickly navigate between controllers and views by right-click menus or CTRL-G, CTRL-M keyboard commands
- MSBuild Task for Compiling Views: A new built-in MSBuild task that includes views in the project compilation process - recommended for staging and deployment activities.
- View Refactoring Support: Using the Rename refactoring command in VS2008 will ensure that files and folders under the \Views application sub-folder get automatically updated when you rename controller classes or action methods.
ASP.NET MVC Add View to Controller Action Method
There are also a number of other improvements including View Improvements, Form Post Improvements, Unit Test Improvements, Cross Site Request Forgery (CSRF) Protection, File Handling Improvements and AJAX Improvements. You can read Scott Guthrie's detailed review on all the new features to the RC on his blog.
ASP.NET MVC Add/Customize Scaffold Template
Microsoft is late to the game when it comes to implementing the MVC framework. It's been in wide use for Java and PHP for a number of years. Late as it is though, it looks like it has finally arrived and will help Microsoft developers create and test enterprise level web applications.
MVC or Web Forms?
While they aren't yet over, the days of the ASP.NET PostBack may be dwindling. That being said, there are reasons you may want to continue developing web applications using Web Forms including the fact that it's faster to develop with (there's less code and implements the Page Controller pattern), manages state easier using View State or server-based forms and preserves state over HTTP. All this to say that web-forms are easy to understand and develop and are probably fine for most web applications.
You will want to consider the MVC pattern when you want full control over the application, have a big development team that can be split into different roles for the development process (i.e., user interface developers, business logic developers) and want to implement Test Driven Development (TDD) practices.
The ASP.NET MVC package works with Visual Studio 2008 and with the free Visual Web Developer 2008 -- though we expect that it'll be the heavier hitters using the full Visual Studio that will be jumping on this geek wagon.