How to Save Money on Understanding The Model View Controller Pattern
The MVC pattern separates applications into three main layers—models, views, and controllers. One of the benefits of this pattern is the separation of concerns, also called the Single Responsibility Principle (SRP), which makes it possible to develop, debug, and test application features independently.
When using the ASP.NET MVC pattern, a user request is routed to a Controller, which will use a Model for retrieving data and performing actions.
The Controller selects a corresponding view for a display to the user while providing it with the necessary data from the Model. There is less impact if a layer (for example, Views) changes since it is now loosely coupled to the other layers of your applications (for example, controllers and models).
It is also much easier to test the different layers of your applications. In the end, you will have better maintainability and more robust code by using this pattern:
Models
A Model contains the logical data structures as well as the data of your applications, independent from their visual representations. In the context of ASP.NET Core 2.0, it also supports localization and validation, as you have seen in the previous chapters.
Models can be created in the same project with your views and controllers or in a dedicated project for the better organization.
Scaffolding uses models for autogenerating views.
Furthermore, models can be used to bind forms to entity objects automatically. In terms of data persistence, various data storage targets can be used. In the case of databases, you should be using Entity Framework, which will be introduced in one of the following chapters of this book. Models are serialized when working with Web APIs.
Views
A View provides the visual representation and user interface elements for your applications. When using ASP.NET Core 2.0, views are written using HMTL and Razor markup. They generally have a .cshtml file extension.
A View either contains a complete web page, a web page part (called partial view), or a layout. In ASP.NET Core 2.0, a View can be separated into logical subdivisions with their behaviors, which are called View Components.
Additionally, Tag Helpers allow you to centralize and encapsulate HTML code in a single tag and use it across all your applications. ASP.NET Core 2.0 already includes many existing Tag Helpers for improving developer productivity.
Controllers
A Controller manages the interactions between models and views. It provides logical behavior and business logic for your applications. It chooses which View has to be rendered for a specific user request. Generally speaking, since controllers provide the main application entry point, this means that they are controlling how applications should respond to user requests.
For more additional information to follow .net online course
