ASP. net mvc Overview (C #)

Source: Internet
Author: User
Document directory
  • Advantages of MVC-based web programs
  • Advantages of web forms-based programs

The Model-View-controller (MVC) architecture model divides an application into three components: model, view, and controller. The ASP. Net MVC framework provides an alternative solution for creating MVC-based Web applications. ASP. net MVC Framework is a lightweight, highly tested display framework (web forms-based applications) that inherits the existing ASP. NET features, such as master pages and membership permissions. The MVC framework is defined inSystem. Web. MVCUnder the namespace and isSystem. WebThe basic and Support Section of the namespace.

MVC is a standard design model that many developers are familiar. Web applications using MVC will benefit from this, while other unused Web applications will continue to use traditional web forms and post-release ASP. NET application mode, and some web programs will be used in combination with the two, but the two are irrelevant.
The MVC framework consists of the following three parts:

Figure 01: Call a controller action with a parameter value (click to view the full size)

  • Model. The model object is part of the application's data domain logic. Generally, model objects access the model status in the database. For example, a product object can obtain information from the SQL Server database, operate on it, and write the updated information back to the products table.

In small applications, models are generally separated by concepts rather than physically. For example, if an application only reads a dataset and sends it to the view, the application does not need a physical model layer or isolation class. In this case, the dataset plays the role of the model object.

  • ViewThe. view is an integral part of the Application User Interface (UI. Generally, this UI is created from model data. For example, the edit view of the Products table uses several input boxes. The drop-down box and check box are used to indicate the status of the current products object.

 

  • ControllerThe. controller processes user interaction, interacts with the model, and finally selects the view used to display the UI. In MVC applications, the view only displays information. The controller processes and responds to user input and interaction. For example, the controller processes the query string values and transmits these values to the model. In turn, the model uses these values to query the database.

The MVC pattern helps you divide applications into several different aspects (input logic, business logic, and UI logic), reducing coupling between these aspects. This mode specifies where each logic should be located in the application. The UI Logic belongs to the view. The input Logic belongs to the Controller. The Business Logic belongs to the model. This division helps you manage complexity when generating an application, because it allows you to focus only on one implementation aspect at a time. For example, you can focus only on views instead of business logic.

In addition to management complexity, it is easier to use MVC mode to test programs than web forms-based applications. For example, in an ASP. NET web program based on a web form, a simple class is required to display the output and respond to user input. Is a web form-based ASP. for example, to test individual pages, you have to instantiate the page class, its sub-controls, and the dependent classes in other programs. Since so many classes are instantiated to run web pages, it is difficult to focus only on the part of individual pages in the test program. ASP. NET program tests based on web forms become more difficult to implement than MVC programs. Moreover, ASP. NET programs based on web forms require a web server. The MVC Framework decouples components and extensively uses interfaces, which makes it possible to separate individual components from other frameworks for testing.

The loose coupling of the three components in the MVC application promotes parallel development. For example, one developer can make a view, the other can make a controller logic, and the third can focus on the business logic in the model.

Determine when to use the MVC Program

You must consider whether to use the ASP. net mvc framework or the ASP. NET web form model to implement web applications. The MVC Framework does not replace the web form model. Both frameworks can be used to develop web programs. (If you are already using a web form-based program, it is correct to continue using them .)
Before you decide to use the MVC framework or web form model for a website, you 'd better weigh the two.

Advantages of MVC-based web programs

The ASP. net mvc framework has the following two advantages:

  • Applications are divided into models, and views and controllers facilitate management complexity.
  • You do not need to use view State or server forms. This makes the MVC framework very suitable for developers who want to completely control program behavior.
  • Use the frontend controller mode to process web application requests through a simple controller. This allows you to design and support a wide range of Routing infrastructure applications. For more information, see the front-end controller on the msdn website.
  • Better support for test-driven development (TDD ).
  • Suitable for web programs supported by large development and design teams that require high control of the entire program behavior.
Advantages of web forms-based programs

Web forms-based programs have the following advantages:

  • Supports the HTTP reserved state event model, which is conducive to web program development in the business pipeline. Web forms-based programs provide dozens of events that support hundreds of server controls.
  • Use the page controller mode to add the page function. For more information, see the page controller on the msdn website.
  • Using view status or server forms makes it easier to manage status information.
  • Suitable for small development and design teams that want to use a large number of components for rapid development.
  • Generally, program development is less complex, because components (page classes, controls, and so on) are tightly integrated and require less code than the MVC model.
ASP. net mvc framework features

The ASP. net mvc Framework provides the following features:

  • Applications are divided into program tasks (input logic, business logic, and UI logic) by default, testability, and test-driven development (TDD ). The core protocol in the MVC Framework is based on interfaces and can be tested by using simulated objects. simulated objects are the objects in the program that simulate actual object behavior. You do not have to run ASP. NET processes to perform unit tests on programs, which makes unit tests faster and more reliable. You can use any unit test framework compatible with. NET Framework.
  • Scalable and pluggable frameworks. ASP. net mvc framework components can be easily replaced and customized. You can insert your own view engine, URL routing policy, serialization of Action method parameters, and other components. The ASP. net mvc Framework supports both dependency injection (DI) and control inversion (IOC) Container models. Di allows you to inject objects into the class, rather than relying on the class to create the object itself. IOC specifies that if an object requires another object, the first object should be obtained from the external source such as configuration. This makes the test easier.
  • The powerful URL ing component allows you to generate programs that can parse and retrieve URLs. URLs do not need to include file extensions and are designed to support URL naming. This facilitates search engine optimization (SEO) and Table state transition (rest ).
  • You can use existing ASP. NET pages (. aspx files), user controls (. ascx files), master pages (. Master files), and other tag files as view templates. You can use. net MVC framework existing ASP. NET features, such as nested master pages, inline expressions (<% = %>), server controls, templates, data binding, and localization.
  • Supports existing ASP. NET features. ASP. net MVC allows you to use forms authentication and Windows authentication, URL authentication, membership and role, output and data cache, session and profile status management, health monitoring, configure features such as the system and provider architecture.

 

Address: http://www.asp.net/learn/mvc/tutorial-01-cs.aspx

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.