w3resource

MVC Architecture


In the last tutorial, we introduced the ASP.NET MVC and the MVC architecture, in this tutorial, we will explore the MVC architecture in details.

The MVC design architecture have long existed in software engineering. This design patterns spans across almost all the languages, with little or no difference. But in this tutorial, we will be discussing only about MVC as regards ASP.NET

Understanding MVC in ASP.NET

MVC stands for Model, View and Controller. MVC design pattern separates application into three components - Models, Views and Controllers.

Model: Models. Model objects are the parts of the application that implement the logic for the application's data domain. Often, model objects retrieve and store model state in a database. For example, a Product object might retrieve information from a database, operate on it, and then write updated information back to a Products table in a SQL Server database.

models are data and business logics.

View: Views are the components that display the application's user interface (UI). Views sometimes may have to display the model data to the user, as seen in an edit scenario.

views are the application's UI

Controller: Controllers are the drivers that handle user interaction, work with the model, and ultimately determines the view to be shown. In an MVC application, the view only displays information to the user; the controller handles and responds to user requests and interaction. For instance, the controller handles query-string values, and transfers these values to the model, which could be used for database queries.

The following figure illustrates the interaction between Model, View and Controller.

asp.net model view and controller

The following figure illustrates the flow of the user's request in ASP.NET MVC.

The MVC pattern helps you create applications that separate the different aspects of the application (input logic, business logic, and UI logic), while providing a loose coupling between these elements. The pattern specifies where each kind of logic should be located in the application. The UI logic belongs in the view. Input logic belongs in the controller. Business logic belongs in the model. This separation helps you manage complexity when you build an application, because it enables you to focus on one aspect of the implementation at a time. For example, you can focus on the view without depending on the business logic.

asp.net view without depending on the business logic

The loose coupling between the three main components of an MVC application also promotes parallel development. For instance, one developer can work on the view, a second developer can work on the controller logic, and a third developer can focus on the business logic in the model.



Inviting useful, relevant, well-written and unique guest posts