Implementation of MVC design pattern in ASP. NET

Source: Internet
Author: User

This article briefly introduces the implementation of the classic MVC design pattern in the ASP.net environment from three aspects: View, Controller, and model, and discusses the extension of the MVC design pattern, finally, the advantages and disadvantages of MVC are analyzed.

ASP. NET is part of Microsoft's latest New Architecture. NET Framework. It provides powerful support for building a new generation of dynamic websites and distributed network-based applications. Compared with the previous Web development model, ASP. NET provides many important advantages, such as simplicity, security, and manageability. In addition, compared with the process-based ASP page technology, object-oriented technology is fully implemented in ASP. NET. Web Application Instances built with traditional ASP technology implement display, business logic, and process control on pages at the same time, which has many shortcomings from the engineering point of view. The user interface is responsible for displaying the problem model to the user and performing operations and I/O interaction with the user. Users want to maintain relatively stable interactive interfaces, but want to change and adjust the displayed content and format as needed. Under the. NET Framework, the ASP. NET technology works well with the MVC design pattern to solve the above problems.

Introduction to MVC design patterns

Proposed by Trygve Reenskaug, MVC is first applied in the SmallTalk-80 environment and is the basis of interaction and interface systems. The MVC structure is designed for applications that need to provide multiple views for the same data. It achieves the separation between the data layer and the presentation layer. As a development model, MVC is usually used in the design and analysis of distributed application systems, as well as to determine the organizational relationship between various parts of the system. For the requirement of Interface Design variability, MVC (Model-View-Controller) divides the composition of an interactive system into three parts: Model, View, and Controller.

View components display model data, logical relationships, and statuses in a specific form. It obtains the display information from the model and can have multiple different display forms or views for the same information.

The controller is used to process the interaction between users and software. Its responsibility is to control the transmission of any changes in the model and ensure the corresponding connection between the user interface. It accepts user input, the input is fed back to the model to control the calculation of the model. It is a part of the coordination between the model and the view.

The model component stores the data displayed in the view and controlled by the Controller. It encapsulates the computing relationship between the core data, logic, and functions of the problem, it is independent of specific interface expressions and I/O operations.

The separation of models, views, and controllers allows a model to have multiple display views. If you change the model data through the controller of a view, all other views dependent on the data should reflect the changes. Therefore, the Controller will notify all views of the changes at any time, resulting in display updates. This is actually a model change-propagation mechanism.

Implementation of MVC design pattern

ASP.net provides a similar environment for implementing this classic design mode. Developers develop user interfaces on the ASPX page to implement the view. The controller function is implemented in the logic function code (. cs). The model usually corresponds to the business part of the application system. A multi-layer system provided by implementing this design in ASP. NET has obvious advantages over the classic ASP structure implementation system. Separating User display (View) from Action (Controller) improves code reusability. Separating data (models) from the action (Controller) of operations allows you to design a system that is irrelevant to the data stored in the background. In essence, the MVC structure is a method to solve the coupling system problem.

1 View

A view represents a model and provides a user interaction interface. Using multiple user components that contain a single display page, a complex Web page can display content from multiple data sources, and the Web site staff can independently participate in the development and maintenance of these Web pages.

In ASP. NET, view implementation is simple. You can drag the control in the integrated development environment to complete page development, just like developing the Windows interface. This article describes each page in the form of a composite view: a page consists of multiple subviews (User parts; A subview can be the simplest HTML control, server control, or Web custom control nested by multiple controls. The page is defined by the template. The template defines the page layout, the tag and number of user parts. You specify a template and the platform automatically creates a page based on the information. For static template content, such as site navigation, menus, and friendly links on the page, use the default template content configuration. For dynamic template content (mainly business content ), different user requests can only be bound later, and the display content of user parts is filtered for different users. Using a combination page composed of user parts configured according to the template, it enhances reusability and prototype the site layout.

The general process of the view section is as follows: first, the page template defines the page layout; the page configuration file defines the specific content of the view label (user part); then, the page layout policy class initializes and loads the page. Each user part initializes according to its own configuration, loads the validator, sets parameters, and delegates events. After the user submits the request, after the validation of the presentation layer, the user component automatically submits the data to the business entity, that is, the model.

This part mainly defines the basic PageBase of WEB pages, PageLayout of the page layout strategy class, complete the page layout, used to load user parts to the page, and UserControlBase of the user part base class is the user part framework, it is used to dynamically load inspection parts and personalize user parts. To achieve WEB application flexibility, many configuration files are also used in the view section, such as template configuration, page configuration, path configuration, and verification configuration.

  • Three pages in total:
  • Previous Page
  • 1
  • 2
  • 3
  • Next Page

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.