What is ASP. NET MVC? Summarizing ASP. NET MVC

Source: Internet
Author: User
Tags representational state transfer what is asp
ASP. NET MVC Overview

The model-View-controller (MVC) architecture pattern divides an application into three main components: models, views, and controllers. The ASP. NET MVC Framework provides an alternative mode for creating an ASP. NET Web Forms pattern for Web applications. The ASP. NET MVC Framework is a highly testable, lightweight presentation framework that integrates existing ASP. NET features, such as master pages and membership-based authentication, as well as WEB forms-based applications. The MVC framework is defined in the SYSTEM.WEB.MVC assembly.

MVC design Pattern

MVC is a standard design pattern that many developers are familiar with. Some types of WEB applications will benefit from the MVC framework. Some types will continue to use the traditional ASP. NET application pattern based on Web forms and postbacks. Other types of WEB applications will combine these two approaches, both of which are not included in each other.

The MVC framework includes the following components:

Model. A model object is an application part that implements the application data domain logic. Typically, model objects retrieve the model state and store it in a database. For example, the Product object might retrieve information from the database, manipulate that information, and then write the updated information back to the Products table in the SQL Server database.

In a small application, a model is usually a conceptual separation rather than an actual separation. For example, if an application reads only the dataset and sends it to the view, the application does not have a physical model layer and associated classes. In this case, the dataset acts as a model object.

View. A view is a component that displays an application user interface (UI). Typically, this UI is created with model data. The edit view of the Products table is an example of a view that displays text boxes, drop-down lists, and check boxes based on the current state of the Product object.

Controller. A controller is a component that handles user interaction, uses the model, and ultimately selects the view to render to display the UI. In an MVC application, the view displays only information, and the controller is used to process and respond to user input and interaction. For example, the controller processes query string values and passes those values to the model, which the model might use to query the database.

The MVC pattern can help you create applications that separate the different aspects of your application (input logic, business logic, and UI logic) while providing loose coupling between those elements. This mode specifies where each type of logic should be located in the application. The UI logic is in the view. The input logic is located in the controller. The business logic is in the model. By using this separation method when you build your application, you can help simplify it because it allows you to focus on one aspect of implementing your application at a time. For example, you can focus on views that are independent of the business logic.

The loose coupling between these three main components of an MVC application can also facilitate parallel development. For example, a developer can work on a view, a second developer can work on the logic of the controller, and a third developer can focus on the business logic in the model.

Support for test-driven development

In addition to being simplified, using the MVC pattern makes it easier to test your application than a Web Forms-based ASP. For example, in a Web Forms-based ASP. NET Web application, a single class is used both to display output and to respond to user input. Writing automated tests for WEB forms-based ASP. NET applications can be a complex task, because to test a single page, you must instantiate the page class in your application, all of its child controls, and other related classes. Because so many classes are instantiated to run the page, it may be difficult to write tests that focus exclusively on the individual parts of the application. As a result, testing of Web forms-based ASP. NET applications is more difficult to implement than MVC application testing. Also, testing for Web Forms-based ASP. NET applications requires a Web server. The MVC framework separates components and uses them extensively, so that individual components can be tested separately from the rest of the framework.

When to create an MVC application

You must carefully consider whether to use the ASP. NET MVC framework or the ASP. NET Web Forms model to implement the Web application. The MVC framework does not supersede the Web Forms model; You can use either framework for Web applications. (If you have existing WEB forms-based applications, these applications will continue to work exactly the way they always do.) )

Before you decide to use the MVC framework or the WEB forms model for a particular site, weigh the advantages of the various approaches.

The ASP. NET MVC Framework has the following advantages:

By dividing the application into models, views, and controllers, it is easier to simplify the process.

It does not use view state or server-based forms. This makes the MVC framework particularly suitable for developers who want full control over the behavior of the application.

It uses a front-end controller pattern that handles WEB application requests through a single controller. This allows you to design an application that supports a rich routing infrastructure. For more information, see Front Controller (front end controllers).

It provides better support for test-driven development (TDD).

It is ideal for Web applications supported by a large team of developers, and for web designers who need to tightly control application behavior.

Web forms-based frameworks have the following advantages:

It supports an event model that preserves state through HTTP, which is beneficial for developing line-of-business Web applications. Web Forms-based applications provide many of the events that are supported in hundreds of server controls.

It uses page Controller mode to add functionality to a single page. For more information, see page Controller.

It uses view state for server-based forms, which makes it easier to manage state information.

It is ideal for small teams of Web developers and designers who want to quickly develop applications with a large number of components.

In general, it is simpler for application development because components (Page classes, controls, and so on) are tightly integrated and typically require less code than the MVC model.

The ASP. NET MVC Framework has the following features:

Separation, testability, and test-driven development (TDD) of application tasks (input logic, business logic, and UI logic). All core contracts in the MVC framework are interface-based and can be tested using mock objects, which are mock objects that mimic the behavior of the actual objects in the application. You can unit test your application without having to run the controller in an ASP process, which makes unit testing fast and flexible. You can use any unit test framework that is compatible with the. NET Framework.

Extensible and pluggable framework. The purpose of designing ASP. NET MVC framework components is to make it easy to replace or customize them. You can insert 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 control inversion (IOC) container models. DI enables you to inject objects into a class rather than relying on a class to create the object itself. IOC Specifies whether an object requires additional objects, and the first object should get a second object from an external source such as a configuration file. In this way, testing will be much easier.

Extensive support for ASP. NET routing is a powerful URL mapping component that allows you to generate applications with easy-to-understand searchable URLs. URLs do not necessarily contain file extensions and are designed to support URL naming patterns that are well suited for search engine optimization (SEO) and representational state Transfer (REST) addressing.

Supports using tags from existing ASP. NET pages (. aspx files), user controls (. ascx files), and master pages (. master files) in markup files as view templates. You can use existing ASP. NET features such as nested master pages, inline expressions (<%=%>), declarative server controls, templates, data binding, localization, and so on in conjunction with the ASP. NET. NET MVC framework.

Support for existing ASP. ASP. NET MVC allows you to use features such as Forms authentication and Windows authentication, URL authorization, membership and roles, output and data caching, session and profile state management, health monitoring, configuration system, and provider architecture.

"Recommended"

1. Learn more about the difference between ASP. NET MVC and WebForm

2. Detailed description of the ASP (mvc--Controller)

3. Detailed description of the ASP. mvc--View

4. Detailed description of ASP. mvc--Routing

5. Code examples for developing custom menu editing tools with ASP.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.