MVC Architecture

MVC is a software architecture pattern which allows us to split a software application into three interconnected parts. These parts are Model, View, and Controller, in short, they are often known as MVC. Most of the languages like Java, PHP, Python, C# etc use this pattern to develop the applications. In Java, it is known as Spring - MVC Framework, in PHP it is known as cake PHP and so on.

By using the same concept, Microsoft introduced a framework called ASP.Net MVC.

Let's understand the MVC architecture with an image.


Model

Model is an important part of MVC application. It manages the data which is used to represent the output using Views. When a View is designed generally we attach a Model to it. The view requests the data from Model and the Model responds to this request. A Model can also be updated if required.


View

Views are the presentation layer of MVC framework. Views are basically the templates where we write the scripts. Mainly these scripts consist HTML, JavaScript, etc. Although views can have a number of content types as well.

When a user requests an URL, the controller executes and manipulates it and finds the appropriate view. After applying the appropriate logic the controller displays the view to the user. We can not point a view to the browser, they can't be accessed directly.


Controller

Controllers are basically the classes which are responsible to handle the user's request. Controllers deal with the flow of the MVC application, they handle the data coming from the user and responds with a relevant View with a specific Model if required. The controllers can validate the user input they can also make changes to the model as per the user requirements.

The User-defined Controller classes inherit the Controller as a base class and mainly they contain the Action methods.

If you have worked with WebForms application previously then you must have seen that in WebForms application the URL's are basically mapped to the physical files(.aspx pages) directly. But in MVC URL's are mapped to the Controller action methods.