ASP.NET MVC is a framework for building web applications that uses the model-view-controllerpattern.
Like ASP.NET Web Forms, ASP.NET MVC is also built on top of the ASP.NET Framework. This means we can use
same APIs like security, state management, membership, caching,ajax etc in MVC Applications.
Every ASP.NET MVC application has three parts: a model, views, and controllers.
It consists of all the classes that handle data and business logic.
Data processing using model classes is initiated by the controllers that are in charge of user requests.
Once the data processing is complete the controller creates a response to the user by sending the results to a View who then produces HTML to be rendered in the browser.
The model in the MVC pattern represents the parts of the application that implements the data domain logic.
It includes classes representing objects in database (ex:Entity Framework data classes,LINQ To SQL data classes).
Views are the components that show users data fromthe model.
A view page receives a view model object from the controller. The view page contains HTML (and possibly some UI-related
code) to determine how to render the model data back to the browser.
The controllers are classes that collect the user requests, work with the model, and finally select a view to
render the appropriate UI.
When to Use ASP.NET MVC?
• High level of control over the response HTML: Unlike Web Forms, Views in ASP.NET MVC
render HTML exactly as you tell them.
• Easier unit testing: With ASP.NET MVC, it is very easy to follow testing patterns such as test-driven development (TDD).
• Code separation: It refers code separated from one another, as it is divided into model, views, and controllers, which makes it easy to maintain.
What are the Advantages of ASP.NET MVC?
The pattern itself makes it easier to manage complexity by separating the
functionality of the application into three core parts, model, view, and controller.
• ASP.NET MVC web applications do not use view state or server-based forms.
View state can become very large, which is a problem for devices like smartphones running
over slow networks (transmitting all that information can be very slow).
In a Web Forms page,you could only have one
such restriction—that is, you can have as many elements as you like.
• It provides better support for test-driven development (TDD).
• It works very well for web applications that are supported by large teams of developers
and for web designers who need a high extent of control over the HTML .
How ASP.NET MVC Process Requests?
One of the most important concepts to understand about MVC applications is that no relationship exists between a
page request and a physical file inside the web server.
In a traditional Web Forms and Web Pages application, every
page request is translated into a call to a physical file in the webserver. For example, if your request is something
like http://myapp/mypage.aspx, the web server interprets the request by looking at the root of the website for a file
named mypage.aspx.It then processes the file and returns the generated HTML.
In the case of an MVC application, when you makes a request (e.g.,http://myapp/product/list), a component
called routing engine matches the request to a specific route.
A route defines requests using a pattern string and
establishes the controller and method in the controller class that should process the request.
Once the route is identified, the routing engine creates a request handler that in turn will create the controller object that will process
the request (in our example, the controller is “product”). The controller then invokes the method in the controller
class that will process the request (in the example is named “list”). These methods in controller classes that process
requests are called action methods.
When the processing of the request ends, the action method produces a result to
send back to the user. Generally the result is some HTML (rendered by a View) the user will see in the browser.
So we have learned that what is, when to use, what are the advantages and handling requests of MVC Framework. Thanks for reading.