MVC

来源:百度文库 编辑:神马文学网 时间:2024/04/27 21:33:59

Models: Model objects are theparts of the application that implement the logic for the application’s datadomain. Often, model objects retrieve and store model state in a database. Forexample, a Product object might retrieve information from a database, operateon it, and then write updated information back to a Products table in SQLServer.

 

Views: Viewsare the components that display the application’s user interface(UI).Typically, this UI is created from the model data. An example would be an editview of a Products table that displays text boxes, drop-down lists, and checkboxes based on the current state of a Products object.

 

Controllers: Controllers are thecomponents that handle user interaction, work with the model, and ultimatelyselect a view to render that displays UI. In an MVC application, the view onlydisplays information; the controller handles and responds to user input andinteraction. For example, the controller handles query-string values, andpasses these values to the model, which in turn queries the database by usingthe values.

 

MVC & ASP.NET Web Forms

You must consider carefully whether toimplement a Web application by using either the ASP.NET MVC framework or theASP.NET Web Forms model. The MVC framework does not replace the Web Formsmodel; you can use either framework for Web applications.(If you have existingWeb Form-based applications, these continue to work exactly as they alwayshave.)

 

Features of the ASP.NET MVC Framework

TheASP.NET MVC framework provides the following features:

l        Separtion of applicationtasks(input logic, business logic and UI logic), testability, and test-drivendevelopment(TDD) by default. All core contracts in the MVC framework areinterface-based and can be tested by using mock objects, which are simulatedobjects that imitate the behavior of actual objects in the application. You canunit-test the application without having to run the controllers in an ASP.NETprocess, which makes unit testing fast and flexible. You can use anyunit-testing framework that is compatible with the .NET Framework.

l        An extensible and pluggableframework. The components of the ASP.NET MVC framework are designed so thatthey can be easily replaced or customized. You can plug in your own viewengine, URL routing policy, action-method parameter serialization, and othercomponents. You can plug in your own view engine, URL routing policy,action-method parameter serialization, and other components. The ASP.NET MVCframework also supports the use of Dependency Injection(DI) and Inversion ofControl(IOC) container models. DI allows you to inject objects into a class ,instead of relying on the class to create the object it self. IOC specifiesthat if an object requires another object, the first objects should get thesecond object from an outside source such as a configuration file. This makestesting easier.

l        A powerful URL-mappingcomponent that lets you build applications that have comprehensible andsearchable URLs. URLs do not have to include file-name extensions, and are designedto support URL naming patterns that work well for search engineoptimization(SEO) and representational state transfer(REST) addressing.

l        Support for using the markup inexisting ASP.NET page (.aspx files), user control(.ascx files), and masterpage(.master files) markup files as view templates. You can use existingASP.NET features with the ASP.NET MVC framework, such as nested master pages,in-line expression(<%=%>),declarative server controls,templates,data-bingding, localization, and so on.

l        Support for existing ASP.NETfeatures. ASP.NET MVC lets you use features such as forms authentication andWindow authentication, URL authorization, membership and roles, output and datacaching, session and profile state management, health monitoring, the configurationsystem, and the provider architecture.

 

 

参考:MSDN MVC部分