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:

<runtime>

<assemblyBinding xmlns=

"urn:schemas-microsoft-com:asm.v1">

<dependentAssembly>

<assemblyIdentity name="System.Web.Mvc"

publicKeyToken="31bf3856ad364e35"/>

<bindingRedirect oldVersion="1.0.0.0"

newVersion="2.0.0.0"/>

</dependentAssembly>

</assemblyBinding>

</runtime>

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 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:

public abstract class AsyncController : Controller,

      IAsyncManagerContainer, IAsyncController, IController

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:

namespace Test.Areas.Employee

   {

    public class EmployeeAreaRegistration : AreaRegistration

     {

        public override string AreaName

        {

            get { return "employee"; }

        }

 

        public override void RegisterArea(AreaRegistrationContext context)

        {

            context.MapRoute(

                "employee_default",

                "employee/{controller}/{action}/{id}",

                new { action = "Index", id = UrlParameter.Optional }

            );

 

            context.MapRoute(

                "employee_whatsnew",

                "whats-new",

                new { action = "WhatsNew", id = UrlParameter.Optional  }

            );

        }

    }

}

- 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:

public class EmployeeController

{

  public ActionResult View(int id, [DefaultValue(1)]int pageNumber)

  {

 

  }

}


Summary

If you’re looking for ASP.NET MVC hosting, you can always consider ASPHostDirectory as the alternatives. You can start from only $ 3.99/month to get ASP.NET MVC hosting.

What is so SPECIAL on ASPHostDirectory.com .NET MVC Hosting?

We know that finding a cheap, reliable web host is not a simple task so we’ve put all the information you need in one place to help you make your decision. At ASPHostDirectory, we pride ourselves in our commitment to our customers and want to make sure they have all the details they need before making that big decision.

We will work tirelessly to provide a refreshing and friendly level of customer service. We believe in creativity, innovation, and a competitive spirit in all that we do. We are sound, honest company who feels that business is more than just the bottom line. We consider every business opportunity a chance to engage and interact with our customers and our community. Neither our clients nor our employees are a commodity. They are part of our family.

The followings are the top 10 reasons you should trust your online business and hosting needs to us:

- FREE domain for Life - ASPHostDirectory gives you your own free domain name for life with our Professional Hosting Plan and 3 free domains with any of Reseller Hosting Plan! There’s no need to panic about renewing your domain as ASPHostDirectory will automatically do this for you to ensure you never lose the all important identity of your site
- 99,9% Uptime Guarantee - ASPHostDirectory promises it’s customers 99.9% network uptime! We are so concerned about uptime that we set up our own company to monitor people’s uptime for them called ASPHostDirectory Uptime
- 24/7-based Support - We never fall asleep and we run a service that is opening 24/7 a year. Even everyone is on holiday during Easter or Christmast/New Year, we are always behind our desk serving our customers
- Customer Tailored Support - if you compare our hosting plans to others you will see that we are offering a much better deal in every aspect; performance, disk quotas, bandwidth allocation, databases, security, control panel features, e-mail services, real-time stats, and service
- Money Back Guarantee - ASPHostDirectory offers a ‘no questions asked’ money back guarantee with all our plans for any cancellations made within the first 30 days of ordering. Our cancellation policy is very simple - if you cancel your account within 30 days of first signing up we will provide you with a full refund
- Experts in .Net MVC Hosting
- Given the scale of our environment, we have recruited and developed some of the best talent in the hosting technology that you are using. Our team is strong because of the experience and talents of the individuals who make up ASPHostDirectory
- Daily Backup Service - We realise that your website is very important to your business and hence, we never ever forget to create a daily backup. Your database and website are backup every night into a permanent remote tape drive to ensure that they are always safe and secure. The backup is always ready and available anytime you need it
- Easy Site Administration - With our powerful control panel, you can always administer most of your site features easily without even needing to contact for our Support Team. Additionally, you can also install more than 100 FREE applications directly via our Control  Panel in 1 minute!

Happy Hosting!