What Is MVC Architectural Design Pattern? – Session 10

What is MVC - Session10

In this session, we are going to introduce MVC Architectural and talk about it’s workflow in ASP.NET Core. Also, we will talk about Model, Controller, View and their interactions with some examples.

What Is MVC Architectural Design Pattern?

Generally, MVC that refers to Model- View- Controller is an architectural design pattern which divides application into three main parts that we have mentioned. In MVC, users send their request to Controller. then, this part interact with Model to conduct user’s request. In addition, Controller is in charge of choosing proper View in order to display received response to user.

What Is MVC Architectural Design Pattern?

MVC architectural is one of the implementation methods of User Interface Layer. According to it’s complexity, it could include Business Logic Layer and Data Access Layer. As you can see in picture, this architectural is divided into three main parts, Model, Controller, View and each part contains particular section.

sample of MVC Architectural Design Pattern
MVC workflow in ASP.NET Core and request/response cycle

As you can see in above picture, users send their request to application by a browser. Considering the URL and ASP.NET Core MVC routing, it has been sent to proper Controller and Action. Regarding the request, Controller and Action Method will interact with proper Model. Model will produce required data send back the result to Controller. Then, Controller choose proper View and send received data to that and display to user. Also, strongly typed View takes Model structure from Models section.

Controller

As we mentioned, the role of Controller is to receive request and interact with Model to gather required data. In fact, based on default routing in ASP.NET Core each URL request should have two mandatory and one optional section. As you can see below, first part after domain name, point to the Controller. Next part is related to Action Method and third part is to present ID in some cases that act like a Query String.

sample of a Controller in a MVC architectural design

Model

This part is related to classes, repository interfaces and repositories of each entity in a program. Also, it can include Business Login Layer and Data Access Layer section of program. Each entity has a class in Model. Moreover, each entity may have a Repository Interface and a Repository for Entity CRUD operations. Bear in mind that creating Interface Respiratory is not mandatory unless for Dependency Injection. All mentioned points will be described in details during upcoming sessions.

sample of a Model in a MVC architectural design

View

This section is to be displayed in browser. In fact it is a HTML format file that encapsulate CSharp or VB code by means of Razor View Engine. Regarding our considered programming language, the suffixes could be CSHTML or VBHTML. Strongly Type View, receive it’s data structure from Model. Also, this part should have minimum rate of business logic. Most of logic should implement in Model section.

Sample of View in MVC

If you need more details, watch this session video. Also, for being updated about our coming sessions, follow us on Instagram, Facebook, Telegram or YouTube and be in touch with us here.

You can download this Session Slides form HERE

0.00 avg. rating (0% score) - 0 votes

Tags

0 0 votes
Article Rating
guest

0 Comments
Inline Feedbacks
View all comments