Top 7 Features of the ASP.NET MVC Framework

Introduction

ASP.NET MVC framework has been a real advantage for developers to build ASP.NET applications implementing MVC pattern easy, fast and in an efficient manner. Going forward in a project development the manageability of the project becomes much easier because of its loosely coupled nature. In this article I will take you through a list of ASP.NET MVC framework features which I feel to be the top 7 list.

ASP.NET MVC was initially introduced by Microsoft along with .NET framework 3.5 service pack 1 (1.0 version). Now with .NET Framework 4.0 and Microsoft Visual Studio 2010 it comes by default with some added features like templating, areas, etc as ASP.NET MVC2 (2.0 version).

The whole concept revolves around 3 major components:

  1. Model (Represents M)
    Model is generally the business objects responsible for representing the underlying the database schema and would hold the data/state for an MVC application.
  2. View (Represents V)
    This is the UI piece of the application. Generally in ASP.NET MVC application it is a .aspx and .ascx file.
  3. Controller (Represents C)
    This is the heart of ASP.NET MVC framework application which is responsible for rendering the appropriate view to the client, executing the pertinent action method, getting the data from the model and populating the view, getting the data from view and updating the model, etc.

Fig 1.0 is the diagrammatic representation of MVC pattern.

ASP.NET MVC diagrammatic representation of MVC pattern
Fig 1.0

Opens the Gate for Parallel Development

When you create either ASP.NET MVC application or Empty ASP.NET MVC application in Microsoft Visual Studio 2010 you will notice that the Visual Studio IDE creates the folders named Controllers, Views and Models by default and adds it to the solution. The model, controller and view have to be physically separated into different files. Fig 2.0 is the sample solution explorer screenshot.

ASP.NET MVC sample solution explore
Fig 2.0

In major organizations a project constitutes a separate UI team for designing the UI, a Dev team to write the core .NET code and also a data team (managing the model). The main advantage of this loosely coupled architecture is that it allows the different teams of a project to work on its own area without any dependency from another team. For example the UI team can solely work on only the Views without screwing up the code behind or waiting for some C# developer to check-in his changes.

Thus the ASP.NET MVC framework decreases the complexities involved in doing parallel development.

URL Routing – Controllers Serving the Request

Unlike a normal ASP.NET application, the ASP.NET MVC application requests are not made to the files on disk like the .aspx file. Rather the request is made directly to the controller. Below is a sample request URL format.

  http://localhost:34299/<Controller>/<ActionMethodName>

The incoming request would fire the ActionMethod of the controller that is specified in the URL, i.e. the request will be routed to the respective controller’s action method and that method takes the responsibility of rendering back the result view. Why does this matter for a developer? Below is the answer.

  • Similar to REST-like URL based architecture. It also leads to easy manipulation of the URL by the users.
  • Makes the application search engine friendly which is considered to be more important in modern day web application development.

What makes this kind of URL driven architecture possible? The secret lies in the global.asax file. Check out the code below.

  public class MvcApplication : System.Web.HttpApplication
  {
          public static void RegisterRoutes(RouteCollection routes)
          {
              routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

              routes.MapRoute(
                  "Default", // Route name
                  "{controller}/{action}/{id}", // URL with parameters
                  new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
              );

          }

          protected void Application_Start()
          {
              AreaRegistration.RegisterAllAreas();

              RegisterRoutes(RouteTable.Routes);
          }
  }

In the above code you might have noticed how the URL routing is registered and also the default values specified.

More by Author

Must Read