ASP.NET MVC is another option available to ASP.NET developers for creating web applications on the .NET platform.
ASP.NET MVC is an implementation of the MVC pattern. MVC is an architectural pattern which provides guidelines on how to structure the application.It is specially suited to the web applications of today as it provides a loosely coupled approach to structure the application.According to MVC pattern the application is separated into three different components.
Model The Model contains the business entities our application deals with as well as the business logic or business rules for our application.This is usually a class which talks to the database to fetch and update data.
View The view is just a template which is used to generate the user interface such as HTML.
Controller The controller is responsible for accepting user input, performing operations on the model and selecting the view to render.
We can depict the relationship between the Model ,View and Controller with the below diagram.As we can see the controller is the Main component as it coordinates with both the View and the Model.Also note that the View is aware of the Model while Model is not aware of View.The advantage that this provides is that our application is loosely coupled.
MVC pattern separates the application in three main components
The main advantages of using ASP.NET MVC are
Separation of Concerns As the Model,View and Controller are separate we can update or replace any of the components without effecting the rest of the application.This results in better maintenance of the code.
Testability As the controller are independent classes in MVC ,and not tightly coupled to the UI as WebForms , we can very easily unit test the application logic that the controller classes contains.
LightWeight As there is no view state in MVC so the generated HTML is significantly smaller in size as compared to WerbForms.
Control over HTML and CSS In WebForms there is HTML which is generated by the server controls over which we have little or no control.MVC doesn’t have server controls like webforms ,instead we provide the HTML that we want to return to the user.As we write the HTML so we can write HTML that is required.
MVC framework is defined in the System.Web.Mvc assembly.So we need to include this assembly in our MVC applications.
There has been many releases of MVC. The last official release was MVC 5. The preview of MVC 6 is also available now.
MVC 5 which was released as a part of visual studio 2013 has many new features.Some of these features are
ASP.NET Identity The previous membership system has been replaced with ASP.NET identity which provides some nice features such as a authentication using login providers such as twitter.
Supports Bootstrap framework Bootstrap is the most famous HTML, CSS, and Javascript framework for creating responsive and mobile first web sites.It is a totally free framework.
Attribute based routing We can attach the attributes directly to the controller classes and action methods.In the previous versions we can add the routes only in a separate RouteConfig.cs file.
Scaffolding This is a process which generates code based on our model classes.This is an automatic process so we don’t need to write the boilerplate code by hand as the basic structure is generated for us.
So this was just an introduction to ASP.NET MVC framework.The next article Controller in MVC describes controller ,which is one of the most important parts of mvc application, in more detail.