Some basic knowledge about ASP. net mvc Framework

Source: Internet
Author: User
Tags net return

MVC Model-View-Controller) structure mode splits an application into three main components: model, view, and controller. When creating a Web application based on the MVC framework, you can use the ASP. net mvc framework as an important candidate for the ASP. NET Web form mode solution. Compared with Web form-based applications, ASP. net mvc Framework is a lightweight and tested description framework, which can be used with existing ASP. NET features such as master pages and member identity-based authentication) are tightly integrated. The MVC framework is defined in the namespace System. Web. Mvc.

For a long time, MVC is a standard design model that many developers are familiar. Some types of Web applications benefit from the MVC framework, while others will continue to use traditional ASP Based on Web forms and return technology.. NET application mode. Some Types of Web applications may be used together. In short, the MVC framework scheme and the Web form scheme are not mutually exclusive.

In general, the MVC framework includes the following components:

1) model.Model objects are part of the data domain logic of applications. Typically, model objects are also responsible for retrieving and storing model statuses from databases. For example, a product object may retrieve information from a database, operate on the data, and write the update information back to a product table in the SQL Server database.

Tip: In small applications, a model is often a conceptual separation rather than a physical concept. For example, if an application reads only one dataset and sends it to the view, the application does not have to create a physical model layer and associated classes. In this case, the data directly assumes the role of a model object.

2) view.A view is a component that displays the user interface (UI) of an application. In typical cases, this UI is created based on model data. A typical example is the editing view of a product table. In this view, you can display text boxes, drop-down lists, check boxes, and other controls based on the current status of a product object.

3) controller.The Controller component is responsible for processing user interaction and operating models, and finally selects and generates a view to display the UI. In an MVC application, the view is only responsible for displaying information, and the Controller is responsible for processing and responding to user input and interaction. For example, the controller processes the query string values, transmits these values to the model, and then uses this value in the model for database query.

The MVC mode separates different aspects of the application (input logic, business logic, and UI logic) and provides loose coupling between these elements. The MVC pattern requires that each different logic should exist in a specific location in the application. For example, the UI Logic belongs to the view, the input Logic belongs to the Controller, and the business logic belongs to the model. This separation helps you to manage the complexity of building an application because it enables you to focus only on one aspect of implementation at a specific time point. For example, you can focus on the view instead of the business logic.

In addition to management complexity, compared to testing a traditional ASP. NET Web application, MVC-based development makes it easier to test the application. For example, in a traditional ASP. NET Web application, a single class is used to display the output and respond to user input. Therefore, it is a traditional ASP. NET application coding automation testing may be very complicated, because in order to test a single page, you must instantiate the page class, all its child controls, and other dependent classes in the application. In short, you need to instantiate a large number of classes to run the page, so in this case it is much more difficult to write a test for a single part of the application. Therefore, testing traditional ASP. NET applications is much more complex and difficult than testing an application developed using the MVC framework. In addition, a traditional ASP. NET application also needs to use a Web server during testing. In contrast, the MVC Framework separates components and uses a large number of interfaces, which makes it easier to test a single component independently from other parts of the framework.

In addition, the loose coupling between the three main components of an MVC application also promotes parallel development. For example, a developer can develop a view, while another developer is developing the Controller logic. The third programmer can focus on the development of the business logic of the model.

Advantages of Web applications based on MVC Framework

The ASP. net mvc Framework provides the following advantages:

By separating an application into independent models, views, and controllers, the management of application complexity is further improved.

View status or server-based form technology is no longer used. This makes the MVC framework especially beneficial to developers who want to fully control the behavior of an application.

Uses a Front-end Controller (Front Controller) mode and uses a single Controller to process Web application requests. This feature makes it possible to design an application that supports an extremely rich Routing infrastructure. For more information about front-end controllers, see http://go.microsoft.com/fwlink? LinkId = 106357.

Provide strong support for test-driven development (TDD.

Advantages of Web applications based on Web Forms

The traditional Web form-based framework provides the following advantages:

Supports event models. This model can retain the status during HTTP transmission, which is very beneficial to the development of online business Web applications. Web form-based applications provide a large number of events, all of which are supported by hundreds of server controls.

Using a Page Controller) mode, this mode can add many features to a single Page. For more information about the page controller, see http://msdn.microsoft.com/zh-cn/library/ms978764.aspx.

Using view status or server-based forms makes it easier to manage status information.

ASP. net mvc framework features

In summary, the ASP. net mvc Framework provides the following important features:

Separates the basic task input logic, business logic, and UI logic of an application, and supports test and test-driven development (TDD ). All core contracts in the MVC Framework are based on interfaces, so it is very helpful to use mock objects, which are the simulated objects of actual objects in some Simulation Applications) for testing projects. You can perform unit tests on applications without having to run controllers in real ASP. NET processes, which speeds up unit tests and makes them flexible. You can use any unit test framework compatible with the. NET Framework to test your project.

Provides a scalable and pluggable framework. The Design of ASP. net mvc framework components allows users to easily replace or customize them. You can design and add your own view engine, URL routing policy, serialization of behavior method parameters, and other components. The ASP. net mvc framework also supports the use of the existing Dependency Injection, namely, the "Dependency Injection" ("DI") and the control inversion IOC) container model. DI allows you to inject objects into a class, instead of relying on the class to create the object itself. IOC specifies that if an object requires another object, the first object should obtain the second object from an external source such as a configuration file. This support is very helpful for engineering testing.

Implements a powerful URL ing component that allows you to build easy-to-understand and searchable URLs in your applications, rather than the extremely complex expressions in many Web application URLs ). Nowadays, the URL does not need to include the file extension, and its design also supports the URL naming mode. Therefore, this mode is conducive to Search Engine Optimization SEO) and REST declarative state transfer) addressing.

You can use tags in existing ASP. NET pages (. aspx files), user controls (. ascx files), and master pages (. master files) as view templates. You can use ASP.. net mvc framework continues to use existing ASP. NET features, such as nested master pages, inline expressions <% = %>), declarative server controls, templates, data binding, localization, and so on.

Supports existing ASP. NET features. ASP. net mvc Framework supports you to use such as form and Windows authentication, URL Authorization, members and roles, output buffering and data buffering, session and configuration status management, health monitoring, Configuration System, provider architecture, and other ASP. NET features.

URL ing

In typical cases, in an ASP. NET Website, URLs are mapped to files stored on disks (mainly. aspx files ). These. aspx files will include the code or tags to be processed for requests sent to the client.

The ASP. net mvc framework maps URLs to server code in a way different from ASP. NET Website applications. The MVC Framework does not map URLs to ASP. NET pages or HTTP processor programs, but directly maps URLs to specific controller classes. Then, the Controller class is responsible for processing incoming requests, such as user input and interaction, and executing appropriate applications and data logic based on user input. Typically, a controller class calls a separate view component to generate the corresponding HTML output as a response to the request sent by the client.

In the ASP. net mvc Framework, the model, view, and controller components are separated. Typically, the model component maintains the state of persistent data in the database, while the view component is selected by the Controller and finally generates the corresponding UI on the client. By default, ASP. net mvc framework uses existing ASP. NET page (. aspx), master page (. master) and user controls (. ascx) type as the output form on the browser side. The Controller component locates the appropriate behavior methods in the controller, obtains the parameter value used as the behavior method, processes all possible errors during execution, and generates the required view. Each group of components is stored in a separate folder of an MVC Web application project.

By providing a URL ing engine, ASP. net mvc Framework provides considerable flexibility in ing URLs to Controller classes. You can use this ing engine to define routing rules. Then the ASP. net mvc framework uses these routing rules to calculate the sent URL request and select the Controller to execute. You can also enable the routing engine to automatically analyze the variables defined in the URL and enable the ASP. net mvc Framework to pass the content to the Controller as parameters.

MVC Framework and page return

The ASP. net mvc Framework does not use the traditional ASP. NET return model to achieve interaction with the server. Instead, all end-user interactions are routed to a controller class. This helps to keep the separation of UI logic and business logic, and helps test the purpose. The result is that ASP. NET view status and ASP. NET page lifecycle events are not integrated with MVC-based views.

This article is excerpted from Zhu Xianzhong's blog: in-depth analysis of ASP. NET 3.5 MVC framework.

  1. Scott Gu teaches you how to use ASP. net mvc 2 new features
  2. Microsoft released multiple function updates for ASP. net mvc 2 preview Edition
  3. 13 uncertain ASP. net mvc extensions
  4. Learning the basic concepts of ASP. NET MVC
  5. Learning how to use ASP. net mvc Routing

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.