Home  >  Article  >  Backend Development  >  What is ASP.NET MVC? Summary ASP.NET MVC

What is ASP.NET MVC? Summary ASP.NET MVC

零下一度
零下一度Original
2017-05-20 13:32:363746browse

ASP.Net MVC Overview

##Model-View-Controller (MVC) architectural pattern divides an application into three main components: Model, View, and Controller. The ASP.NET MVC framework provides an alternative mode to the ASP.NET Web Forms mode for creating web applications. The ASP.NET MVC framework is a very testable, lightweight presentation framework that (like Web Forms-based applications) integrates 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 Design Pattern

What is ASP.NET MVC? Summary ASP.NET MVC

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 methods; the two methods are exclusive of each other.

The MVC framework includes the following components:

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

In small applications, models are often conceptually separated rather than actually separated. For example, if an application only reads a dataset and sends it to a view, the application does not have a physical model layer and associated classes. In this case, the dataset serves as the model object.

view. Views are components that display the application user interface (UI). Typically, this UI is created using model data. An example of a view is the edit view of the Products table, which displays text boxes, drop-down lists, and check boxes based on the current state of the Product object.

Controller. Controllers are the components that display the UI by handling user interaction, working with models, and ultimately selecting the view to render. In an MVC application, views only display information; controllers handle and respond to user input and interaction. For example, the controller processes query string values ​​and passes these values ​​to the model, which may use these values ​​to query the database.

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

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

Support for test-driven development

Using the MVC pattern can not only simplify the complexity, but also make the application testing work faster than that based on Web forms. Testing ASP.NET web applications becomes easier. 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 endeavor because to test a single page, you must instantiate the page class, all its child controls, and other related classes in the application. Because so many classes are instantiated to run a page, it can be difficult to write tests that focus specifically on a single part of the application. Therefore, testing Web Forms-based ASP.NET applications is more difficult to implement than testing MVC applications. Furthermore, testing of Web Forms-based ASP.NET applications requires a Web server. The MVC framework enables component separation and heavy use of interfaces, so 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 your web application. The MVC framework does not replace the Web Forms model; you can use either framework for your Web applications. (If you have existing Web Forms-based applications, those applications will continue to work exactly the same way they always have.)

Before you decide to use the MVC framework or the Web Forms model for a particular website , please weigh the merits of each approach.

The ASP.NET MVC framework offers the following benefits:

Make complexity easier by dividing your application into models, views, and controllers.

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

It uses a front 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.

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

It is ideal for web applications supported by large teams of developers, as well as web designers who require tight control over application behavior.

The Web Forms-based framework has the following advantages:

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

It uses the page controller pattern to add functionality to a single page. For more information, see Page Controller.

It uses view state for server-based forms, which makes managing state information easier.

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 the components (Page classes, controls, etc.) are tightly integrated and generally require less code than the MVC model.

The ASP.NET MVC framework provides the following features:

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

Extensible and pluggable framework. ASP.NET MVC framework components are designed so that they can be easily replaced or customized. You can plug in your own view engines, URL routing strategies, 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 rather than relying on the class to create the object itself. IOC specifies whether an object requires other objects, the first object should get the second object from an external source like a configuration file. This way, testing will be easier.

Extensive support for ASP.NET Routing, a powerful URL mapping component that allows you to build 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 markup from existing ASP.NET page (.aspx file), user control (.ascx file), and master page (.master file) markup files as view templates. You can combine existing ASP.NET features such as nested master pages, inline expressions (), declarative server controls, templates, data binding, localization, etc. with the ASP.NET MVC framework In conjunction with.

Supports existing ASP.NET functionality. 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 .

【Related recommendations】

1. In-depth understanding of the differences between ASP.NET MVC and WebForm

2. Detailed introduction ASP.NET MVC--controller

3. Detailed introductionASP.NET MVC--View

4. Detailed introduction ASP.NET MVC--Routing

5. Code example for developing WeChat custom menu editing tool through asp.net mvc

The above is the detailed content of What is ASP.NET MVC? Summary ASP.NET MVC. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn