Table of Content
- Introduction
- Model-View-Controller
- Advantage of MVC Pattern
- ASP.NET MVC vs Web Forms
- Conclusion
Introduction
This article explains what MVC is and why to use ASP.NET MVC instead of ASP .NET Web Forms. MVC stands for Model - View - Controller. It is a software architecture pattern that separates the representation of information from the user's interaction with it. Model View Controller has been widely adapted as an architecture for World Wide Web applications in all major programming languages. ASP.NET supports three development models: Web Pages, MVC and Web Form.
Model-View-Controller
MVC consists of three kinds of objects (Model, View and Controller). The Model is the application object, the View is its screen presentation, and the Controller defines the way the user interface reacts to user input. Let's see each of them in brief.
Controller
The Controller is an input control. It first executes when the user sends a request. Then the action determeines which view will be shown. It connects to both the View and the Model. It can send commands to its associated view to change the view's presentation and can also send a command to change the model's state. It processes in the way that it reads data from the view (controls user input) and sends input data to the model. A controller can be associated with multiple views, in other words we can define multiple actions in a controller and depending on the action, an associated view is shown. It is the principal part of the MVC architecture. It is similar to the Business Layer of 3-tier architecture.
Model
A Model is associated with Views and a Controller. It produces the updated output on the view. Often the model objects retrieve data from the database and stores data to the database. It handles the logic for the application's data domain.
View
Views are the components that display the application's User Interface (UI), in other words it manages the displays of information. Often the views are created from the model data. We can attach multiple views to a single model to provide a different presentation (View/Model decoupling).
Advantages of MVC Pattern
There are the following advantages of the MVC pattern:
- Business Logic is independent so it can be used from different presentation tiers.
- Application divided into three the categories of input logic, business logic and UI logic so it is easier to manage complexity of the application.
- It does not use viewstate and postback.
- It provides better support for test-driven development (TDD).
- By separating concerns into 3 distinct pieces (Model, View and Controller), we also facilitate true unit testing. Our Presentation Layer can be tested free of the Model or Controller, and vice-a-versa.
ASP.NET MVC vs Web Forms
- Web Forms embraces the RAD philosophy whereas ASP.NET MVC is TDD-oriented.
- ASP.NET Web form uses server controls but ASP.NET MVC depends on HTML Controls.
- Web application development with Web Form is easy compared to ASP.NET MVC because ASP.NET MVC web application requires experts in HTML and JavaScript.
- The web application is a lighter application with ASP.NET MVC architecture compared to ASP.NET Web Forms because ASP.NET Web Form applications store the view state on a page so it becomes heavy and reduces performance.
- ASP.NET MVC provides powerful URL mapping so it is better for SEO.
Conclusion
The MVC pattern has many advantages by separation of input logic, business logic and UI logic but has some drawbacks that it is fully controlled by HTML, JavaScript and CSS and can't easily learn without experiments.