ASP. NET MVC Overview

Source: Internet
Author: User

ASP. NET MVC Overview

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.net web forms pattern for creating  mvc-based web applications. the asp.net mvc framework is a  lightweight, highly testable presentation framework that  (As with Web  forms-based applications)  is integrated with existing ASP.NET  features, such as master pages and membership-based authentication.  the mvc framework is defined in thesystem.web.mvc namespace and  is a fundamental, 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.

Figure 01: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.

in small applications, the model is often a conceptual  separation instead of a physical one. for example, if the  application only reads a data set and sends it to the  view, the application does not have a physical model layer  and associated classes. in that case, 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 are the components that handle user  Interaction, work with the model, and ultimately select a view  to render that displays ui. in an mvc application, the  view 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 database by using  the values.
  • The mvc pattern helps you create applications that separate the  different aspects of the application  (input logic, business  Logic, and ui logic),  while providing a loose coupling between  these elements. The pattern specifies where each kind of  logic should be 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 you  manage complexity when you build an application, because it  enables you to focus on one aspect of the implementation  at a time. for example, you can focus on the view without depending on  the business logic. 

    In addition to managing complexity, the mvc pattern makes it  easier to test applications than it is to test a web  Forms-based ASP.NET Web application. For example, in a Web  Forms-based asp.net web application, a single class is used both  to display output and to respond to user input. writing  automated tests for web forms-based asp.net applications can be  complex, because to test an individual page, you must  instantiate the page class, all its child controls, and  additional dependent classes in the application. because so many  Classes are instantiated&nbSp;to run the page, it can be hard to write tests that  focus exclusively on individual parts of the application. tests  for web forms-based asp.net applications can therefore be more  difficult to implement than tests in an MVC application.  moreover, tests in a web forms-based asp.net application require  A web server. the mvc framework decouples the components and  makes heavy use of interfaces, which makes it possible to  test individual components in isolation 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.
Deciding 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.)

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

Advantages of an mvc-based WEB application

The ASP. NET MVC Framework offers 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 is the MVC framework ideal for developers who want full control over the behavior of an 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, Seefront controllers on the MSDN Web site.
  • IT provides better support for Test-driven development (TDD).
  • It works for the Web applications that is supported by large teams of developers and Web designers who need a high degre E of control over the application behavior.

Advantages of a Web forms-based Web application

The Web forms-based Framework offers the following advantages:

  • It supports an event model that preserves state over HTTP, which benefits line-of-business WEB application development. The Web forms-based application provides dozens of events 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 well for small teams of Web developers and designers who want to take advantage of the large number of components Available for rapid application development.
  • In general, it's less complex for application development, because the components (the Page class, controls, and so on) a Re tightly integrated and usually require less code than the MVC model.
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 are  Interface-based and can be tested by using mock objects, which  are simulated objects that imitate the behavior of actual  objects in the application. you can unit-test the application  Without having to run the controllers in an asp.net process,  which makes unit testing fast and flexible. you can use  any unit-testing framework that is compatible with the .net  framework.
  • An extensible and pluggable framework. the components of the asp. Net mvc framework are designed so that 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 models. 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&Nbsp;first objects should get the second object from an outside  source such as a configuration file. This makes testing  Easier.
  • a powerful url-mapping component that lets you build applications  that have comprehensible and searchable URLs. URLs do not  Have to include file-name extensions, and are designed to support  URL naming patterns that work well for search engine  optimization  (SEO)  and representational state transfer  (REST)  addressing.
  • support for using 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  (<%= %>), 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.

The model-View-controller (MVC) architecture pattern divides the application into three main components: models, views, and controllers. Asp. The NET MVC Framework provides an alternative to ASP. NET Web Forms create patterns based on an MVC Web application. Asp. The net MVC framework is a lightweight, highly testable reporting framework (Applications with Web Forms) that are combined with existing ASP. Network features, such as the home page and membership-based authentication. Thesystem.web the definition of the MVC framework. The MVC namespace is a basic support system. A part of the namespace.


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. The network application pattern is based on Web Forms, postbacks. Other types of Web applications will combine these two methods, and do not rule out other methods.

Figure 1: Expected parameter values invoke the Controller action (click to view full-size picture)


Model. A partial application of a model object that implements the application's logical data domain. Typically, model object retrieval and model state are stored in a database. For example, a Product object might retrieve information from the database, manipulate it, and then write back the Update information table for the product in Sql server.
 


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


. The view is the component Application user interface (UI) that is displayed. Typically, this UI is created from model data. An example would be an edit view of a product table that displays a text box, a drop-down list, and a check box based on the current state of the Product object.
 


Controller. The controller's components handle user interaction, use the model, and ultimately select a view to display the rendering of the UI. In an MVC application, the view displays only information, and 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 can help you create different aspects of a separate application application (input logic, business logic, and UI logic) while providing loose coupling between these elements. The mode specifies that the various logic should be located in the application. The UI logic belongs to the view. The input logic belongs to the controller. belongs to the business logic model. This separation helps manage complexity when building an application, because it allows you to focus on one aspect of the implementation. For example, you can focus on the view without the business logic.


In addition to managing complexity, the MVC pattern is easier to test an application than an ASP that tests a Web form. A NET Web application. For example, ASP in a Web form. A NET Web application that uses a class to display output and respond to user input. ASP for Web Forms to write automated tests. A Web application can be complex because testing a single page, you must instantiate the page class, it's all child controls, and the extra dependent class of the application. Because many classes instantiate run pages, it is difficult to write tests that focus on the parts of the application. Test the ASP for the Web form. Network applications can therefore be more difficult to implement MVC applications than testing. Additionally, test the ASP for a Web form. Network applications require a Web server. The MVC framework decouples the components so that the interfaces are heavily used, which allows it to test the framework of individual components individually.


The loosely coupled MVC application between the three main components also facilitates parallel development. For example, a developer can use the controller logic on a view, and a third developer can focus on the model of the business logic.

Deciding when to create an MVC application


You must carefully consider whether you want to implement a Web application by using ASP. NET MVC framework or ASP. NET Web Form model. The MVC framework does not replace the Web Form model, and you can use the framework of the Web application. (If you have an existing Web Form application, these continue to work because they always have.) )


Before you decided to use the MVC framework or a Web Form model for a specific Web site, weigh the benefits of each approach.




Advantages of an MVC-based Web application


Asp. The NET MVC Framework provides the following benefits:


This makes it easier to manage the complexity of dividing applications into models, views, and controllers.
It does not use view state or server-based form. This makes the MVC framework suitable for developers who want full control over the behavior of the application.
It uses a front-end controller pattern to handle Web application requirements

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.