Introduction
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 estable 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:
Model represents shape of the data and business logic.It maintains the data of The application. Model objects retrieve and store model state in a database.
Note - Model is a data and business logic.
View:
View is a user interface. View display data using model to the user and also enables them to modify the data.
Note - View is a User Interface.
Controller:
Controller
handles the user request. Typically, user interact with View, which
in-tern raises appropriate URL request, this request will be handled by a
controller. The controller renders the appropriate view with the model
data as a response.
Note - Controller is a request handler.
MVC Architecture
The following figure illustrates the flow of the user's request in ASP.NET MVC See Above-.
Request/Response in MVC Architecture
As per the above figure, when the user enters a URL in the browser, it
goes to the server and calls appropriate controller. Then, the
Controller uses the appropriate View and Model and creates the
the response and sends it back to the user.
Why do we use MVC?
Model-view-controller (MVC) is an architectural pattern used in software engineering. In complex computer applications that present a large amount of data to the user, a developer often wishes to separate data (model) and user interface (view) concerns, so that changes to the user interface will not affect data handling, and that the data can be reorganized without changing the user interface. The model-view-controller solves this problem by decoupling data access and business logic from data presentation and user interaction, by introducing an intermediate component: the controller.Model:
The domain-specific representation of the information that the application operates. Domain logic adds meaning to raw data (e.g., calculating whether today is the user's birthday, or the totals, taxes, and shipping charges for shopping cart items).
Many applications use a persistent storage mechanism (such as a database) to store data. MVC does not specifically mention the data access layer because it is understood to be underneath or encapsulated by the Model.
View:
Renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes.
Controller:
Processes and responds to events, typically user actions, and may invoke changes on the model.
MAIN ADVANTAGE OF USING MVC
1. Faster development process.
2. Easier to manage complexity (divide and conquer).
3. It does not use server forms and view state.
4. Front Controller pattern (rich routing).
5. Better support for test-driven development.
6. Ideal for distributed and large teams .
7. High degree of control over the application behavior.
8. Enables the full control over the rendered HTML.
9. Provides clean separation of concerns(SoC).
10. Enables Test Driven Development (TDD).
11. Easy integration with JavaScript frameworks.
12. Following the design of stateless nature of the web.
13. RESTful urls that enables SEO.
14. No ViewState and PostBack events.
ASP .NET MVC Features
- Separation of application tasks
- –Input logic, business logic, UI logic Support for test-driven development –
- Unit testing
- –No need to start app server
- Extensible and pluggable framework
- –Components easily replaceable or customized(view engine, URL routing, data serialization,…)
0 comments :
Post a Comment