What is ASP.NET MVC?
Do you know what is ASP.NET MVC?
Hi everyone, first of all, I am starting this blog to talk about .NET and things related for developers and everybody who wants to know more about this universe.I am going to explain for you what is MVC today, MVC is nothing more than a Design Pattern.
The Model-View-Controller (MVC) architectural pattern separates an application into three main components: the model, the view, and the controller.The ASP.NET MVC framework provides an alternative to the ASP.NET Web Forms pattern for creating Web applications. The ASP.NET MVC framework is a lightweight, highly testable presentation framework that (as with Web Forms-based applications) is integrated with existing ASP.NET features, such as master pages and membership-based authentication. The MVC framework is defined in the System.Web.Mvc assembly.
Model: Nothing more than a class. Yes, it is just a class, but a class that stores the attributes needed for the application, model has all the business, all the data manipulation. Summing up, model is a class with everything you need to manipulate data.
Simple Mvc Model |
View: View is the HTML that users will see, Views uses the Razor Engine, implementing the use of Helpers (I will write about Helpers soon). You can also use Models to bind the data.
Simple View Code |
View in Browser |
Controller: Is the middle between Model and View. Receive all the requests from user.
Controller |
Let's see a chat with Model, View and Controller:
Controller: Hey Model, user wants to login in LinkedIn, please take these data and validate if is this ok!
Model: This is right, user can login.
Controller: Thanks Model. View, the data are right, I am going to send you user's data, and you, please, load the profile page.
View: Thanks, I am loading.
MVC'S Advantages
- It makes it easier to manage complexity by dividing an application into the model, the view, and the controller.
- It does not use view state or server-based forms. This makes the MVC framework ideal for developers who want full control over the behavior of an application.
- It uses a Front Controller pattern that processes Web application requests through a single controller. This enables you to design an application that supports a rich routing infrastructure.
- It provides better support for test-driven development (TDD).
- It works well for Web applications that are supported by large teams of developers and for Web designers who need a high degree of control over the application behavior.