New Features in ASP.NET MVC 2.0

WEBINAR:On-Demand

Introduction

Microsoft's ASP.NET is a language and platform-neutral technology, arguably, one of the most successful web technologies ever. You can use it to design and develop web applications that can run on top of the managed environment of .NET Framework and inside the context of the IIS web server. Microsoft's MVC Framework is based on the time-tested and proven MVC Design Pattern and provides you a framework for building scalable, robust, high-performance web applications seamlessly. Applications designed using the MVC Design Pattern is easier to test and maintain. This article takes a look at the new features in ASP.NET MVC 2.0 and how one can leverage them in applications.

Getting Started with ASP.NET MVC 2.0

To work with ASP.NET MVC 2.0, you need to install it separately if you are using Microsoft Visual Studio 2008. Alternatively, you can use any one of the following versions of Microsoft Visual Studio 2010 - ASP.NET MVC Framework 2.0 is built-in.

Note that ASP.NET MVC Framework can be installed side by side with your ASP.NET MVC 1.0 and you can easily upgrade your ASP.NET MVC 1.0 applications to ASP.NET MVC 2.0 counterparts with ease. Moreover, Visual Studio 2010 has an built-in upgrade wizard that you can use to migrate your existing ASP.NET MVC 1.x applications to ASP.NET MVC 2.0 counterparts seamlessly. To migrate your old ASP.NET MVC 1.0 applications to ASP.NET MVC 2.0 applications manually, you should replace all occurences of "System.Web.Mvc, Version=1.0.0.0" with "System.Web.Mvc,Version=2.0.0.0", replace the old assemblies with newer ones, and also use bindingRedirect element in the web.config file of your ASP.NET MVC 1.0 application as shown below:

Looking Back in Time

ASP.NET MVC Framework 1.0 was released as an external component to Microsoft Visual Studio 2008. The Community Technology Preview of ASP.NET MVC was launched in December 2007. ASP.NET MVC 1.0 was released in March 2009 and ASP.NET MVC 2.0 RTM was released in March 2010.

Understanding the Model View Controller Design Pattern

The Model View Controller (or MVC as it is commonly called), is a proven design pattern that facilitates testability and easier maintenance of the application's code. It also promotes a cleaner separation of the application's concerns and is primarily based on the following major architectural components:

The Model - the component that is responsible for storing the application's data and business logic components

The View - the component responsible for invalidating the view based on the model's state and presenting the data to the user in the user interface

The Controller - the component responsible for managing the interaction amongst these components

The primary advantage of this design pattern is easier maintenance, reduced cost and a cleaner isolation of the application's concerns.

What is the ASP.NET MVC Framework?

The ASP.NET MVC Framework is a framework from Microsoft that can be used to design and implement applications based on the MVC Design Pattern. The basic advantages of using the ASP.NET MVC Framework include: a cleaner separation of concerns, better code organization, extensibility, scalability and code reusability. It also provides an excellent support for a REST-based model and all existing ASP.NET features. As the ASP.NET MVC framework is built on top of the ASP.NET runtime, you can leverage the existing ASP.NET features like authentication and authorization, profile settings, localization, and so on.

Scott Guthrie states in his blog: "One of the benefits of using an MVC methodology is that it helps enforce a clean separation of concerns between the models, views and controllers within an application. Maintaining a clean separation of concerns makes the testing of applications much easier, since the contract between different application components are more clearly defined and articulated."

New Features in ASP.NET MVC 2.0

WEBINAR:On-Demand

New Features in ASP.NET MVC Framework 2.0

ASP.NET MVC 2 is the new version of ASP.NET MVC Framework - a framework for developing highly testable and maintainable Web applications by leveraging the Model-View-Controller (MVC) design pattern. Here is the list of the new features and enhancements in ASP.NET MVC Framework 2.0:

Support for templated helpers - This is a new feature that you can use to associate templates with views for editing and displaying values based on a particular data type.

Support for Asynchronous Controllers - You can now use controllers in ASP.NET MVC 2.0 applications to process requests asynchronously.

The abstract class AsyncController in the System.Web.Mvc namespace provides support for asynchronous operations for controller classes in ASP.NET MVC 2.0. Here is how this class looks like:

The AsyncManager in the System.Web.Mvc.Async namespace provides support for asynchronous
operations to the AsyncController class.

Support for areas - You can use this new feature to partition and group functionalities in your ASP.NET MVC projects. This is a great new feature introduced in ASP.NET MVC 2.0. Areas enable you to organize ASP.NET MVC Applications to manage the complexity of large web applications seamlessly. In essence, an area is used to represent a section of a web site that is comprised of a group or a collection of related controllers, views, routes and sections. When you create a new area, Microsoft Visual Studio automatically adds a class that derives from AreaRegistration class to register the area and its routes. Here is an example:

Support for data annotations - You can use this feature to easily attach validation rules to the Model and View Model classes in your ASP.NET MVC applications.

Support for strongly typed UI helpers - You can use this new feature to perform a compile-time check of the views. This feature also facilitates an enhanced Intellisense support for your view templates in an ASP.NET MVC application.

Support for Templates and Templated Helpers - The introduction of templates is a major new feature in ASP.NET MVC Framework 2.0. Similar to Dynamic Data for WebForms, this is a feature that allows you to display or edit an object of a simple data or complex type. You can have the following types of templates in ASP.NET MVC Framework 2.0:

Default Template
Custom Object Template
Master Page Template

You can use Templated Helpers to create display and edit templates for various types. Templated
Helpers enable you to have a compile time check and provide support for intellisense and code
refactoring.

Support for Client-Side Validation -

ASP.NET MVC 2.0 provides excellent support for client side validation. You can use attributes from the System.ComponentModel.DataAnnotations namespace. An an example, you can make a property or field mandatory using the [Required] attribute as shown in the code snippet below:

[Required]
public string FirstName { get; set;}

The other attributes you can use include: Range, RegularExpression and StringLength

Support for DefaultValueAttribute in Action-Method Parameters - This is yet another great new feature that allows you to pass default values as parameters to the action methods in your ASP.NET MVC 2.0 applications. Here is an example:

Summary

In this article we examined the new and enhanced features in ASP.NET MVC 2.0 - a web application development framework based on the MVC Design Pattern. This article has provided an a head start to learning the new features and enhancements in ASP.NET MVC 2.0 for designing and implementing high performant, testable, maintainable, scalable, robust, web applications seamlessly. Happy reading!

Advertiser Disclosure:
Some of the products that appear on this site are from companies from which QuinStreet receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. QuinStreet does not include all companies or all types of products available in the marketplace.

Thanks for your registration, follow us on our social networks to keep up-to-date