ASP. NET MVC Overview

Source: Internet
Author: User

Goal: Learn the differences between ASP. NET MVC and ASP. NET WebForm. Learn to use ASP. NET MVC in the right place.

The MVC (Model-view-controller) architecture pattern separates an object into 3 chunks: model (data Model layer), view layer, controller (control layer), and ASP. NET. NET MVC Framework provides a different The WebForm model provides an MVC-based Web Page object. ASP. NET MVC is a lightweight, highly testable display framework (compared to WebForm) and incorporates the features of existing ASP, such as master pages and member-based validation. The MVC framework is defined under the System.Web.Mvc namespace and this is a basic namespace. and supports the system.web namespace section.

MVC is a standard design pattern that is widely known by many developers. Some types of Web applications will benefit from ASP, others will continue to use the traditional WebForm pattern and use postbacks, and some applications will combine MVC and webform to make them feel similar, of course, Nor does it preclude other methods.

The MVC framework includes the following components:

Step: Call the Controller's action and bring its own parameter values.

    • model Layer (MODELS): Model objects are part of a program that implements the logic of the application data domain. Generally speaking, model object retrieval and storage models are stated in the database. For example, a Product object might retrieve information from a database, manipulate it, write update information, and then pass it back to the product table in the SQL Server database.

In small programs, models are often separated theoretically, and certainly not physically separated. For example, if the program simply reads a data set and then returns the dataset to view, the program does not have a physical model layer associated with the class. In that case, the dataset actually plays the role of a model object.

    • View layer (views): A view is a "container" on which the program is displayed on the screen (UI). Generally speaking, the interface is actually created from the model object. An example, a view of an editable product table, with some textbox, drop-down box (DropDownList), and some checkboxes, of course, are based on the Product object.
    • control Layer (Controllers): The control layer handles user interaction, works with the model layer, and chooses a view to render some components of the displayed UI. In an MVC application, the view layer is simply responsible for displaying the information, controlling the layer processing, and replying to the user to enter information to achieve an interactive effect. For example: The control layer processes the value of the query string (query-string) and then passes these values to the model, which in turn can query the database with these values.

The MVC pattern helps you create applications to achieve different aspects of separating applications (input logic, business logic, UI logic) to achieve low coupling between objects. The MVC pattern specifies that each type of logic must be built on top of the application. The UI logic actually belongs to the view. The input logic belongs to the controller, and the business logic belongs to model. Layered mode can help you manage well when you build your application, because it allows you to focus on some aspect of the implementation sometimes. For example, when you focus on the view you don't have to worry about the model thing = =.

In addition to the ease of management, the MVC pattern is much simpler to test the application than the WebForm pattern. For example, in a WebForm program, a separate class often uses 2 files to display the output and the input of the postback user. Writing an automated test may be complicated for webform-based applications, because to test a standalone page, you have to instantiate the page's corresponding class, and all of the child controls will make it difficult to focus on some part of the application without paying attention to other places, So the advantages of the MVC pattern are apparent. In a deeper sense, the WebForm program requires a Web Server, and the MVC framework makes it possible to isolate individual components from other frameworks by reducing coupling between components and by using interfaces extensively.

Low coupling also guarantees parallel development between the m-v-c components of an MVC application. For example, there were 3 developers, one developer focused on the control layer, another developer focused on the view layer, and the last developer focused on building a model layer.

  Deciding when to use the MVC pattern is appropriate

You have to be very careful when considering when to use the MVC framework or WEBFORM.MVC does not completely replace WebForm, you can choose one as the cornerstone of your application development.

Before you decide to use the MVC Framework or WebForm to implement your site, weigh the advantages of each.

  The advantages of the MVC framework

The MVC framework has several advantages:

    • makes it easier to fully control the separation of an object into a M-V-C3 layer pattern.
    • Do not use view state and server controls. This makes the MVC framework more ideal for developers (with full control over the behavior of the application)
    • The front-end control pre-mode is used for requests via Web applications (one controller alone). This allows you to design your application to support multiple routing structures, and if you want to see more about front Controller, you can view its MSDN documentation.
    • There is better support for TDD.
    • For large projects (where a large number of people are in a team), it is important to control the behavior of the application efficiently.

Advantages of WebForm

WebForm's advantages include the following points:

    • Support Event Model save state on HTTP, suitable for linear business web development, the WebForm program provides many events to support a large number of server controls.
    • Use the page Controller mode to add individual pages individually, see here for more->pgae Conroller
    • ViewState or server forms are used, which makes it easier to control state information.
    • Small team, or a team that wants to develop quickly with a large number of server controls.
    • Overall, the development process is relatively less complex, because components (page classes, controls, and so on) are tightly combined, and there is not so much code relative to the MVC pattern.

  Features of the ASP. NET MVC pattern

The ASP. NET MVC framework has the following features:

    • implements separation of application tasks (input logic, business logic, Interface logic), testability, and default TDD. All core classes are interface-based in the MVC framework and can be tested by simulated objects. Simulation objects can be used to simulate the behavior of the actual program in the program. You can do unit tests. In an ASP. NET application, you can make unit tests fast and comfortable without using a controller. You can use any of the unit tests to test different versions of the. Net Framework.
    • A framework that is extensible and plug-in. ASP. NET MVC components are designed to be easily replaced or customized. You can insert in your own view engine, URL routing rules, action method parameter serialization, and other components. The MVC framework also supports the use of dependency injection and the control reversal container model. Dependency injection allows you to inject objects into the class, in addition to relying on the class to create the object itself. Control reversal Specifies that if an object requires another object, the first object should get a second object from the external resource, such as a settings file (such as Web. config), which is easier.
    • A powerful url-mapping component that allows you to create understandable and queryable URLs. URLs do not contain file name suffixes, and design URL naming patterns are very good for search engine SEO and represent state transport addressing.
    • supports the use of tags in an existing ASP. NET page (aspx file), a user control (ascx file), a master page (. master file), You can easily use existing ASP features in the MVC framework, such as embedded master pages, single-line expressions (<%= = =), stating server controls, templates, data binding, localization, and so on.
    • supports the existing features of ASP. MVC will allow you to use these features such as form validation and Windows validation, URL authorization, members and roles, output and data caching, session and brief state management, health monitoring, provisioning systems, and providing architecture.

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.