One of the first novelties straight from PDC 2009 is the release of ASP.NET MVC 2 Beta for Visual Studio 2008. You can download ASP.NET MVC 2 Beta from Microsoft Downloads here.
For the newcomers, here’s a quick description of the technology:
“ASP.NET MVC 2 is a framework for developing highly testable and maintainable Web applications by leveraging the Model-View-Controller (MVC) pattern. The framework encourages developers to maintain a clear separation of concerns among the responsibilities of the application – the UI logic using the view, user-input handling using the controller, and the domain logic using the model. ASP.NET MVC applications are easily testable using techniques such as test-driven development (TDD).
The installation package includes templates and tools for Visual Studio 2008 SP 1 to increase productivity when writing ASP.NET MVC applications. For example, the Add View dialog box takes advantage of customizable code generation (T4) templates to generate a view based on a model object. The default project template allows the developer to automatically hook up a unit-test project that is associated with the ASP.NET MVC application. Because the ASP.NET MVC framework is built on ASP.NET 3.5 SP 1, developers can take advantage of existing ASP.NET features like authentication and authorization, profile settings, localization, and so on.”
New features in this release include:
New RenderAction Method
Html.RenderAction (and its counterpart Html.Action) is an HTML helper method that calls into an action method from within a view and renders the output of the action method in place. Html.RenderAction writes directly to the response, whereas Html.Action returns a string with the output. RenderAction works only with actions that render views.
Strongly Typed UI Helpers
ASP.NET MVC 2 includes new expression-based versions of existing HTML helper methods. The new helpers include the following:
- ValidationMessageFor
- TextAreaFor
- TextBoxFor
- HiddenFor
- DropDownListFor
TempDataDictionary Improvements
The behavior of the TempDataDictionary class has been changed slightly to address scenarios where temp data was either removed prematurely or persisted longer than necessary. For example, in cases where temp data was read in the same request in which it was set, the temp data was persisting for the next request even though the intent was to remove it. In other cases, temp data was not persisted across multiple consecutive redirects.
Client Validation Library
MicrosoftMvcAjax.js now includes a client-side validation library that is used to provide client validation for models in ASP.NET MVC.
“Add Area” Dialog Box
ASP.NET MVC 2 Beta includes a new Add Area context menu item when you right-click either the root project node or the Areas folder (if one exists). If a root Areas folder does not already exist, the command creates one, and it then creates the files and folders for the area that you specify.
Calling Action Methods Asynchronously
The AsyncController class is a base class for controllers that enables action methods to be called asynchronously. This lets an action method call external services such as a Web service without blocking the current thread. For more information, see Using an Asynchronous Controller in ASP.NET MVC In the ASP.NET MVC 2 documentation.
Blank Project Template
In response to customer feedback, an empty ASP.NET MVC project template is now included with ASP.NET MVC 2 Beta. This empty project template contains a minimal set of files used to build a new ASP.NET MVC project.
Multiple Model Validator Providers
ASP.NET MVC 2 Beta lets you register multiple validation providers.
Multiple Value Provider Registration
In ASP.NET MVC 2 Beta, the single value provider that was available in ASP.NET MVC 1.0 has been split into multiple value providers, one for each source of request data. The new value providers include the following:
- FormValueProvider
- RouteDataValueProvider
- QueryStringValueProvider
- HttpFileCollectionValueProvider
These value providers are registered by default. You can register additional value providers that pull data from other sources.
Download Microsoft ASP.NET MVC 2 Beta here (2.2 Mb).