An MVC web application is built using a model-view-controller software design architecture, that helps in the development of user interfaces, data, and business logic.
The Model-View-Controller (MVC) software design pattern was created in the 1970s. It promotes the separation of concerns by isolating the domain model and controller code from the user interface (view), which simplifies maintenance and testing.
The MVC design pattern divides an application into three major components: Model, View, and Controller
The Model is a collection of classes that describe both the business logic (business model) and the data access activities (data model). It also sets business rules for data, specifying how it can be altered and manipulated.
Model Binding automatically converts form inputs into model properties. In controllers, model binding is used to connect form data to model parameters in action methods.
The ViewModel class is designed exclusively for views. It can mix properties from many models or add new characteristics required for the view.
The View represents UI components such as CSS, jQuery, and HTML. It is solely responsible for showing the data received from the controller as the result. This also converts the model(s) to UI.
The view is necessary to display the user interface on the browser. It's necessary to make your application engaging and user-friendly. To use a client-side framework such as AngularJS, ReactJS, etc.
A Normal View in ASP.NET MVC renders HTML content for the browser, much like a webpage in ASP.NET WebForms. It is used to provide data to the user and usually comprises HTML, Razor syntax, and server-side code.
A Partial View is similar to user control in ASP.NET Web Forms. It is a reusable view component that can be embedded into other views and is useful for rendering web page parts such as headers, footers, and reusable widgets.
A Layout View works similarly to a master page in ASP.NET Web Forms. It creates a uniform structure for many views by defining common HTML elements (such as headers, footers, and navigation menus) that are shared across the application's pages.
The view includes the following language-dependent extension:
The Controller is responsible for processing incoming requests. It gets input from users via the View, processes the data using the Model, and returns the results to the View. Typically, it serves as a liaison between the View and Model.
Controllers can be defined by generating classes that derive from the System.Web.Mvc.Controller is a base class. Each controller class name normally ends in "Controller" (for example, HomeController).
Action Methods refer to methods found within a controller class. Action methods process HTTP requests and return an ActionResult. Common ActionResult types include ViewResult, JsonResult, RedirectToRouteResult, and so on.
ASP.NET MVC uses a routing process to connect URLs to controller operations. Routes are defined in the RouteConfig class, which is normally located in the App_Start folder.
An action method produces a result. It can be of several types:
ASP.NET MVC automatically converts HTTP request data into action method parameters. It supports complex type parameters, simple types, and collections.
Filters are used to run code before or after action methods. Filters are classified as Authorization, Action, Result, or Exception. Filters are applied using attributes such as [Authorise], [HandleError], and [OutputCache].
Dependency Injection
ASP.NET MVC provides dependency injection, which improves the separation of concerns and testability. It can be configured in Startup.cs or using IoC containers such as Autofac, Ninject, and so on.