ASP. NET MVC Overview

Source: Internet
Author: User
Tags representational state transfer

Learn about the differences between ASP application and ASP. NET Web Forms applications. Learn how to decide when to build an ASP. NET MVC application.

 Learn about the differences between ASP. NET MVC applications and ASP. NET Web forms applications. Learn how to decide when to build an ASP. NET MVC application.

the Model-view-controller (MVC) architectural Pattern separates an application into three main components:the model, the view, and the controller. The ASP. NET MVC Framework provides an alternative to the ASP. Web Forms pattern for creating mvc-based Web applications . The ASP. NET MVC Framework is a lightweight, highly testable presentation framework (as with Web forms-based Applicati ONS) is integrated with existing ASP. Features, such as master pages and membership-based authentication. The MVC framework is defined in the SYSTEM.WEB.MVC  namespace and was a fundamental, supported part of the  system.web  namespace. 

model-View-controller (MVC) architecture pattern divides an application into three main components: model, views and controllers. asp.net MVC Framework provides an alternative way to create an ASP. NET Web Forms pattern for Web applications that are based on MVC. asp.net MVC Framework is a lightweight, highly testable presentation framework (as with WEB forms-based applications) combined with existing ASP. NET features, such as master pages and membership-based authentication. MVC framework is defined in the System.Web.Mvc namespace and is a basic, supported Part of the system.web namespace.

MVC is a standard design pattern, many developers is familiar with. Some types of the WEB applications would benefit from the MVC framework. Others would continue to use the traditional ASP. Application pattern is based on Web Forms and postbacks. Other types of WEB applications would combine the approaches; Neither approach excludes the other.

 MVC is a standard design pattern that many developers are familiar with. Some types of WEB applications will benefit from the MVC framework. others 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 approaches; two ways to exclude others.

The MVC framework includes the following components:

The MVC framework includes the following components:

  

figure: Invoking a controller action, expects a parameter value (Click to view full-size image)

    • Models. Model objects is the parts of the application that implement the logic for the application s data domain. Often, model objects retrieve and store model state in a database. For example, a Product object might retrieve information from a database, operate on it, and then write updated Informatio n Back to a Products table in SQL Server.

Figure  : A controller action that invokes an expected ( Click to view full-size picture ) parameter value

    • model . a Model object is an application part that implements the logic of the application's data domain. Typically, model objects are retrieved and the model state is stored in the database. For example, a product object may retrieve information from the database operation on it, and then write the updated information back to the Product table in SQL Server.

In small applications, the model is often a conceptual separation instead of a physical one. For example, if the application is reads a data set and sends it to the view, the application does does have a physical m Odel layer and associated classes. The data set takes on the role of a model object.

    • views. Views is the components of that display the application S user interface (UI). Typically, this UI was created from the model data. An example would is an edit view of a Products table this displays text boxes, Drop-down lists, and check boxes based on t He current state of a Products object.

    • Controllers. Controllers is the handle user interaction, work with the model, and ultimately select a view to render T Hat displays UI. In an MVC application, the view is only displays information; The controller handles and responds to user input and interaction. For example, the controller handles query-string values, and passes these values to the model, which in turn queries the D Atabase by using the values.

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

    • 's Views . A view is a component that displays the user interface (UI) of an application. Typically, this UI is created by model data. The example displays a text box, a drop-down list, and a check box based on the editing view of the product table for the current state of a Product object.

    • controller . a controller is a component that handles user interactions, models, and ultimately selects the view to render to display the UI. In an MVC application, the view displays only information; The controller processes and responds to user input and interaction. For example, the controller processes query string values and passes those values to the model, which in turn queries the values used by the database.

The MVC pattern helps you create applications that separate the different aspects of the APPLICAT Ion (input logic, business logic, and UI logic), while providing a loose coupling between these elements. The pattern specifies where each kind of logic should is located in the application. The UI logic belongs in the view. Input logic belongs in the controller. Business logic belongs in the model. This separation helps your manage complexity when you build a application, because it enables you-to-focus on one aspect O f the implementation at a time. For example, your can focus on the view without depending on the business logic. 

MVC patterns can help you create standalone applications (input logic, business logic, and UI logic), It also provides the application of different aspects of loose coupling between these elements. This mode specifies where each logic should be placed in the application. The user interface logic belongs in the view. The logic of the input belongs to the controller. business logic belongs to the model. For example, you can focus on having no view based on business logic.

  In addition to managing complexity, the MVC pattern makes it easier to test applications than it's to test a Web forms- Based ASP. NET WEB application. For example, in a Web forms-based ASP. NET Web application, a single class was used both to display output and to respond to User input. Writing automated tests for Web forms-based ASP. Applications can complex, because to test a individual page, you m UST instantiate the page class, all its child controls, and additional dependent classes in the application. Because so many classes is instantiated to run the page, it can is hard-to-write tests that focus exclusively on Individu Al parts of the application. Tests for Web forms-based ASP. Applications can therefore is more difficult to implement than Tests in an MVC Applicati On. Moreover, tests in a Web forms-based ASP. Application require a Web server. The MVC framework decouples the components and makes heavy use of interfaces, which makes it possible to test individual C OmpOnents in isolation from the rest of the framework. 

  In addition to managing complexity, the MVC pattern makes it easy to test applications instead of testing a Web form based on an ASP. NET Web application. For example, in a Web form that is based on an ASP. NET Web application, a separate class is used to display the output and respond to user input. Web forms that write automated tests based on an ASP. NET application can be complex because to test a single page, you must instantiate the page class, all child controls, and other related classes in the application. because so many classes are instantiated to run the page, it can be difficult to write tests that specifically focus on the various parts of the application. therefore, testing for WEB forms-based ASP. NET applications can be more difficult to implement than testing in an MVC application. In addition, a Web server is required for testing in Web Forms-based ASP. The MVC framework enables components to be used in a large number of interfaces, allowing it to test individual components separately from the rest of the framework.

The loose coupling between the three main components of an MVC application also promotes parallel development. For instance, one developer can work on the view, a second developer can work on the controller logic, and a third develop Er can focus on the business logic in the model.

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

Deciding when to Create an MVC applicationdeciding when to create an MVC application

You must consider carefully whether to implement a WEB application by using either the ASP framework or the ASP. NET Web Forms model. The MVC framework does not replace the WEB Forms model; You can use the either framework for WEB applications. (If you had existing WEB forms-based applications, these continue to work exactly as they always had.)

 You must carefully consider whether to implement WEB applications by using the ASP. NET MVC framework or the ASP. NET Web Forms model. The MVC Framework cannot replace the WEB forms model; for WEB applications, you can use any kind of framework. (if you have an existing WEB forms-based application, these continue to work exactly as they always have).

Before decide to use the MVC framework or the Web Forms model for a specific Web site, weigh the advantages of each AP Proach.

 Before you decide to use the MVC framework or Web Forms model for a specific Web site, weigh the advantages of each method.

Advantages of an mvc-based WEB application

The ASP. NET MVC Framework offers the following advantages:

the benefits of MVC-based WEB applications

The ASP. NET MVC Framework has the following advantages:

    • It makes it easier to manage complexity by dividing a application into the model, the view, and the controller.
    • It does not use view state or server-based forms. This makes, the MVC framework ideal for developers who want full control over the behavior of a application.
    • It uses a Front controller pattern that processes WEB application requests through a single Controller. This enables is a application that supports a rich routing infrastructure. For more information, See front controller on the MSDN Web site.
    • It provides better support for Test-driven development (TDD).
    • It works for Web applications is supported by large teams of developers and web designers who need a high D Egree of control over the application behavior.
    • It is easy to divide the application into the complexities of model, view, and controller management.
    • It does not use view state or server-based forms. This makes the MVC framework particularly suitable for developers who want full control over the behavior of the application.
    • It uses a single-controller front-end controller mode to process WEB application requests. This enables you to design applications that support a rich routing infrastructure. For more information, see Front-end controllers on the MSDN Web site.
    • It provides better support for test-driven development (TDD).
    • It is ideal for developers of large teams supported by Web applications and for Web designers who require a high degree of control over the behavior of the application.
Advantages of a Web forms-based Web application

The Web forms-based Framework offers the following advantages:

Advantages of Web Forms based on Web applications

The Web forms framework has the following advantages:

    • It supports an event model this preserves state over HTTP, which benefits line-of-business WEB application Devel Opment. The Web forms-based application provides dozens of events that is supported in hundreds of server controls.
    • It uses a Page Controller pattern that adds functionality to individual pages. For more information, See page controller on the MSDN Web site.
    • It uses view state or server-based forms, which can make managing state information easier.
    • It works for small teams of Web developers and designers who want to take advantage of the large number of compon Ents available for rapid application development.
    • in general, it's less complex for application development, because the components (the  Page &nbs P;class, controls, and so on) is tightly integrated and usually require less code than the MVC model.
    • It supports an event model that facilitates the development of a reserved state for line-of-business Web applications over HTTP. Web Forms-based applications provide many events that support hundreds of server controls.
    • It uses a page controller mode to add functionality to a single page. For more information, see page Controllers on the MSDN Web site.
    • It makes it easier to manage state information by using view state or server-based forms.
    • It is ideal for small teams of Web developers and designers who want to take advantage of a large number of components available to quickly develop applications.
    • In general, it is less complex for application development because components ( Page classes, controls, and so on) are tightly integrated and typically require less code than the MVC model.
Features of the ASP-net MVC Framework

The ASP. NET MVC Framework provides the following features:

features of the ASP. NET MVC Framework

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) by default. All core contracts in the MVC framework is interface-based and can be tested by using mock objects, which is simulated O Bjects that imitate the behavior of actual objects in the application. You can unit-test the application without have to run the controllers in an ASP. Which unit makes FA St and flexible. You can use any of the unit-testing framework. Compatible with the. NET Framework.
  • The
  • an extensible and pluggable framework. The components of the ASP. NET MVC framework is designed so, they can be easily replaced or customized. You can plug in your own view engine, URL routing policy, 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 mode Ls. DI allows inject objects into a class, instead of relying on the class to create the object itself. IOC specifies that if a object requires another object, the first objects should get the second object from a outside so Urce such as a configuration file. This makes testing easier.
  • A powerful url-mapping component that lets you build applications that has comprehensible and searchable URLs. URLs do not have the to include File-name extensions, and is designed to the support URL naming patterns H engine Optimization (SEO) and representational state Transfer (REST) addressing.
  • The markup in existing ASP. NET page (. aspx files), user control (. ascx files), and master page (. master Files) markup files as view templates. You can use existing ASP. NET features with the ASP. NET MVC framework, such as nested master pages, in-line expressions (&L t;%=%>), declarative server controls, templates, data-binding, localization, and so on.
  • Support for existing ASP. Features. ASP. NET MVC lets you use features such as forms authentication and Windows authentication, URL authorization, membership a nd roles, output and data caching, session and profile state management, health monitoring, the configuration system, and The provider architecture.
  • Separate application tasks (input logic, business logic, and UI logic), testability, and test-driven development (TDD) are by default. all core contracts in the MVC framework are interface-based objects that can be tested by using mock objects, which mimic the behavior of objects in the actual application. You can unit test the application without running the controller in the ASP. NET process, which makes unit testing both fast and flexible. You can use any unit test framework that is compatible with the. NET Framework.
  • Extensible and pluggable framework. the components of the ASP. NET Framework are designed so that they can be easily replaced or customized. You can insert your own view engine, URL routing policy, action method parameter serialization, and other components. the ASP. NET MVC Framework also supports the use of the Dependency injection (DI) and control inversion (IOC) container models. DI allows you to inject an object into a class rather than relying on a class to create the object itself. IOC Specifies whether an object requires another object, and the first object should get a second object from an external source such as a configuration file. this makes testing easier.
  • A powerful URL mapping component that allows you to build applications with understandable and searchable URLs. URLs do not have to include file extensions and are designed to support URL naming patterns, work well with search engine optimization (SEO) and representational state transfer (REST) processing.
  • Use existing ASP. NET pages (. aspx files), user controls (. ascx files), and markup files in the master page (. master file) as support for view templates. You can use existing ASP. NET features with the ASP. NET-MVC framework, such as nested master pages, lines in expressions (<%=%>), declaring server controls, templates, data binding, localization, and so on.
  • Support for existing ASP. ASP. NET MVC allows you to use 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 capabilities.

ASP. NET MVC Overview

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.