Introduction To ASP.NET MVC
What is MVC?
MVC is a framework methodology. It divides an application’s implementation into three component roles: models, views, and controllers.
- The Model represents the application core (for instance a list of database records).
- The View displays the data (the database records).
- The Controller handles the input.
For example: If you request a page, first controller handle the request and order a action which will serve the request. Action can use model to get database record. Then action displays results to the view pages. MVC provides full control over HTML, CSS and JavaScript.
You can think MVC model defines web applications with 3 logic layers:
- The business layer (Model logic)
- The display layer (View logic)
- The input control (Controller logic)
The Model is the part of the application that handles the logic for the application data. Often model objects retrieve data (and store data) from a database.
The View is the parts of the application that handles the display of the data. Most often the views are created from the model data.
The Controller is the part of the application that handles user interaction. Typically controllers read data from a view, control user input, and send input data to the model.
The MVC separation helps you manage complex applications, because you can focus on one aspect a time. For example, you can focus on the view without depending on the business logic. It also makes it easier to test an application.
The MVC separation also simplifies group development. Different developers can work on the view, the controller logic, and the business logic in parallel.
A Look at MVC Request Response process
From the above discussion, you may guess the Request Response process of MVC. Let us try to see this formally.
- User sends the request by the URL.
- UrlRoutingModule intercepts the request and starts parsing it.
- The appropriate Controller and handler will be identified from the URL by looking at the RouteTable collection. Also any data coming along with the request is kept in RouteData.
- The appropriate action in the identified controller will be executed.
- This action will create the Model class based on data.
- The action will then pass on this created model class to some view and tell the view to proceed.
- Now the view will execute and create the markup based on the logic and Model’s data and then push the HTML back to the browser.
This life cycle above is defined for explanation and has omitted some technical details.
What is View Engine?
View Engines are responsible for rendering the HTML from your views to the browser. The view engine template will have different syntax for implementation. Currently there are few numbers of view engines available for MVC and the top four view engines are Razor, traditional ASPX, Spark and NHaml.