What Is MVC
What Is MVC
MVC Components
Following are the components of MVC −
Model
The Model component corresponds to all the data-related logic that the user works with. This can
represent either the data that is being transferred between the View and Controller components or
any other business logic-related data. For example, a Customer object will retrieve the customer
information from the database, manipulate it and update it data back to the database or use it to
render data.
View
The View component is used for all the UI logic of the application. For example, the Customer
view will include all the UI components such as text boxes, dropdowns, etc. that the final user
interacts with.
Controller
Controllers act as an interface between Model and View components to process all the business
logic and incoming requests, manipulate data using the Model component and interact with the
Views to render the final output. For example, the Customer controller will handle all the
interactions and inputs from the Customer View and update the database using the Customer
Model. The same controller will be used to view the Customer data.
ASP.NET MVC
ASP.NET supports three major development models: Web Pages, Web Forms and MVC (Model
View Controller). ASP.NET MVC framework is a lightweight, highly testable presentation
framework that is integrated with the existing ASP.NET features, such as master pages,
authentication, etc. Within .NET, this framework is defined in the System.Web.Mvc assembly.
The latest version of the MVC Framework is 5.0. We use Visual Studio to create ASP.NET
MVC applications which can be added as a template in Visual Studio.
ASP.NET MVC Features
Thus, you can consider MVC Framework as a major framework built on top of ASP.NET
providing a large set of added functionality focusing on component-based development and
testing.
MVC Framework - Architecture
Advertisements
Previous Page
Next Page
In the last chapter, we studied the high-level architecture flow of MVC Framework. Now let us
take a look at how the execution of an MVC application takes place when there is a certain
request from the client. The following diagram illustrates the flow.
Flow Steps
Step 1 − The client browser sends request to the MVC Application.
Step 2 − Global.ascx receives this request and performs routing based on the URL of the
incoming request using the RouteTable, RouteData, UrlRoutingModule and MvcRouteHandler
objects.
Step 3 − This routing operation calls the appropriate controller and executes it using the
IControllerFactory object and MvcHandler object's Execute method.
Step 4 − The Controller processes the data using Model and invokes the appropriate method
using ControllerActionInvoker object
Step 5 − The processed Model is then passed to the View, which in turn renders the final output.
MVC and ASP.NET Web Forms are inter-related yet different models of development,
depending on the requirement of the application and other factors. At a high level, you can
consider that MVC is an advanced and sophisticated web application framework designed with
separation of concerns and testability in mind. Both the frameworks have their advantages and
disadvantages depending on specific requirements. This concept can be visualized using the
following diagram −
Comparison Table
Let us jump in and create our first MVC application using Views and Controllers. Once we have
a small hands-on experience on how a basic MVC application works, we will learn all the
individual components and concepts in the coming chapters.
Create First MVC Application
Step 1 − Start your Visual Studio and select File → New → Project. Select Web → ASP.NET
MVC Web Application and name this project as FirstMVCApplicatio. Select the Location as
C:\MVC. Click OK.
Now, Visual Studio will create our first MVC project as shown in the following screenshot.