In this article describe the concept of mvc in asp.net. The MVC (model view controller) architectural pattern separates an application into three main components: the model, the view, and the controller. Here we describe about mvc, model, view, controller, and its benefits, and features.
The MVC is stands for model view controller. The MVC architectural pattern separates an application into three main components: the model (the business layer), the view (the display layer), and the controller (the input control). 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. MVC is used for reduce complexity of the application.
MVC is a standard design pattern that many developers are familiar with. Some types of Web applications will benefit from the MVC framework. Others will continue to use the traditional ASP.NET application pattern that is based on Web Forms and postbacks. Other types of Web applications will combine the two approaches; neither approach excludes the other.
MVC includes the following components:
The Model is the part of the application that handles the logic for the application data. Often, model objects retrieve and store model state in a database. For example, a User object might retrieve information from a database, operate on it, and then write updated information back to User table in a SQL Server database.
The Model represents a set of classes that describes the business logic and data. It also defines business rules for how the data can be changed and manipulated.
In the MVC, models in asp.net handles the data layer by using ORM tool like Entity framework, NHibernate, etc. When you create when your project then by default Model exist in model folder.
Models can be divided into several parts:
1. Objects or ViewModel Layer
This layer contains simple objects or complex objects which are used to specify strongly-typed view. These objects are used to pass data from controller to strongly-typed view and vice versa. The classes for these objects can have specific validation rules which are defined by using data annotations. Typically, these classes have those properties which you want to display on corresponding view/page.
2. Data Access Layer
This layer provides objects to access and manipulate the database of your application. Typically, this layer is made by using ORM tools like Entity Framework or NHibernate etc.
3. Business Layer
This layer helps you to implement your business logic and validations for your application. This layer make use of Data Access Layer for persisting data into database. Also, this layer is directly invoked by the Controller to do processing on input data and sent back to view.
Views are the components that display the application's user interface (UI). View is the responsible for converting a model into UI. The Model is responsible for providing all the required business logic and validation to the view. The view is only responsible for displaying the data that is received from the controller as the result. View is by default in the view folder.
The Controller is the responsible for controlling the application logic. It works as mediator that access both the model data and the view data. The controller get the user’s data from the view, and send for the process user’s data with the help of model and then passing the results back to the view.
By default controller is stored in the Controller folder.
MVC vs Web From based application
You must consider carefully whether to implement a Web application by using either the ASP.NET MVC framework or the ASP.NET Web Forms model. The MVC framework does not replace the Web Forms model; you can use either framework for Web applications. (If you have existing Web Forms-based applications, these continue to work exactly as they always have.)
Advantages of mvc based web application
There are some advantages of mvc based web application:
· It makes to easier to manage because the application divided into model, view 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.
Advantages of web form based application
There are some advantages of web form based application:
· It supports an event model that preserves state over HTTP, which benefits line-of-business Web application development. The Web Forms-based application provides dozens of events that are supported in hundreds of server controls.
· It uses a Page Controller pattern that adds functionality to individual pages.
· It uses view state on server-based forms, which can make managing state information easier.
· It works well for small teams of Web developers and designers who want to take advantage of the large number of components available for rapid application development.
· In general, it is less complex for application development, because the components (the Page class, controls, and so on) are tightly integrated and usually require less code than the MVC model.
Features of ASP.NET MVC
There are some useful features of mvc:
· Separation of application tasks (business logic, UI logic, and input logic) and testability test driven development (TDD). All core contracts in the MVC framework are interface-based and can be tested by using mock objects, which are simulated objects that imitate the behavior of actual objects in the application. You can unit-test the application without having to run the controllers in an ASP.NET process, which makes unit testing fast and flexible. You can use any unit-testing framework that is compatible with the .NET Framework.
· In the mvc, the components of the ASP.NET MVC framework are designed so that they can be easily replaced or customized. You can plug in your own view engine, URL routing policy, action-method parameter serialization, and other components. The ASP.NET MVC framework also supports the use of Dependency Injection (DI) and Inversion of Control (IOC) container models. DI enables you to inject objects into a class, instead of relying on the class to create the object itself. IOC specifies that if an object requires another object, the first objects should get the second object from an outside source such as a configuration file. This makes testing easier.
· Extensive support for ASP.NET routing, which is a powerful URL-mapping component that lets you build applications that have comprehensible and searchable URLs. In the mv URLs does not support the file name extension, and are designed to support URL naming patterns that work well for search engine optimization (SEO) and representational state transfer (REST) addressing.
· In the mvc also supports the .aspx files, user control (.ascx) file and master file as markup file in view in the application. You can use the existing asp.net features using inline code <% %> data binding, localization, etc.
· MVC also supports existing features of authentication and windows authentication, url authorization, membership and roles, output and data caching, session and profile state management, etc.
I hope you will learn from the above article. Thanks to very much!