Introduction to Asp.Net MVC

Asp.Net MVC is the Microsoft web application development framework built on top of the .NET framework. It has several versions, and the latest one is the Asp.Net MVC 6.0. Before going to what is Asp.Net MVC, first, we discuss about what are the web application platforms Microsoft had introduced before Asp.Net MVC and what are the disadvantages of them which cause the implementation of Asp.Net MVC.

ASP: Microsoft first answer to web development was classic ASP (Active Server Page). ASP is the scripting language where code and markup authored together in a single file with the file extension as .asp. Each of this file corresponds to one web page. It was very popular, and many websites developed in ASP. However, later developers want many more features like code reuse, better separation of code from markup, and object-oriented programming principles…etc.

Asp.Net: After classic ASP, Microsoft introduced the Asp.Net in 2002. Asp.Net answered many of the developer’s requirements. Like classic ASP, Asp.Net also rely on file-based approach where each web page represents in the form of a physical file with extension .aspx. However, in Asp.Net there is a separation between code and markup. Markup file name extension is .aspx whereas code file name extension is like .aspx.cs. Many websites and web applications developed using Asp.Net. Still many developers are using Asp.Net web application development platform. Asp.Net has been serving for many years as web application development, but some developers Asp.Net web form approach is the too much abstraction underlying HTML content.

To fulfill the web developer’s need, Microsoft then developed the new web application development platform Asp.Net MVC. The first version of Asp.Net MVC got released in 2008, and the latest version is Asp.Net MVC 6.0.

Unlike Classic Asp and Asp.Net, Asp.Net MVC does not rely on page-based approach. Model, View, and Controllers play the main role in Asp.Net; in my next articles, we discuss more about each in further articles. In Asp.Net MVC, the controller receives the request and passes to Model. Model returns data to Controller; then Controller passes the data to View which displays the data by using HTML as shown below.

 

As indicated above, Controller receives the request from a user, it process and passes to Model if it has to return any data. Model is simply a class, and it can return any data. Once Model returns data, then controller simply passes the data to View. View just displays the data in HTML. The view does nothing other than displaying data as a template.

As of now we just discussed what Asp.Net MVC is, now we discuss about why we need Asp.Net MVC as already Asp.Net web forms is there for web application development.

Why Asp.Net MVC:

  1. We can easily develop any web application by using Asp.Net. However, after six months or later if we want to add any enhancement or to do modifications to existing code, it is tough as our code did not follow any structure. Moreover, it is tough to test our new code independently. Asp.Net MVC solves all these issues, because by using MVC we can develop the application in a structured format and we easily perform the Unit testing for different blocks independently.
  2. In Asp.Net MVC, we have more classes and number of methods but with tiny bit code inside. So maintainability is very easy.
  3.  We can easily control our code, URL’s, and HTML properties (like id) of web controls in Asp.Net MVC. Whereas in Asp.Net, we cannot control asp.net web control id’s and it is not very easy to change the URLs.
  4.  In Asp.Net, all control’s data stored in View State and this view state passes server for each request through HTTP protocol which affects the server performance. Whereas in Asp.Net MVC, we do not have any view state.
  5.  In Asp.Net MVC individual components do not directly depend on other components which give more flexibility to develop components in isolation, can do unit testing each component independently and finally maintaining the application also very easy.


As of now, we discussed what Asp.Net MVC is and why we need Asp.Net MVC. In my next articles, we discuss Model, View, and Controller in-detail.