mvc1 mode: The view receives user input and passes the command to the controller MVC2 mode: In MVC1, the model can notify the view, and then the view can be updated. This is very common in Windows programs, such as the frame-document-view architecture of MFC. If the document changes, it will actively notify the view to update. However, in the web, after the Java bean as the model is updated, the JSP as the view cannot be called (and there are usually many views and you need to choose one), so the MVC2 mode is changed: The view receives user input and passes the command to the controller ASP.NET MVC 3 adds a number of features to ASP.NET MVC 1 and 2, making the code more streamlined and deeply extensible. This article provides descriptions of many of the new features included in this release. Razor View Engine Razor now provides some new features: Razor also includes new HTML Helpers, such as: Support for multiple view engines <br /> In ASP.NET MVC3, the Add View dialog allows you to select the view engine you want. In the New Project dialog, you can specify the default view engine for the project. You can choose WebForm, Razor, or an open source view engine such as Spark, NHaml, or NDjango. Controller improvements New ViewBag Properties New ActionResult Types <br /> The following ActionResult types are new or extended in MVC3. JavaScript and Ajax Improvements <br /> By default, in MVC3, Ajax and validation use unobtrusive JavaScript. Unobtrusive does not insert inline JavaScript into the HTML, which makes the HTML more concise and less intrusive, and also makes it easier to replace and customize JavaScript libraries. In MVC3, validation helpers are done by default using the jQuery.Validate plugin. If you want to use the MVC2 behavior, you can turn off unobtrusive in the web.config configuration. Client validation is enabled by default In earlier versions of MVC, you needed to explicitly call the Html.EnableClientValidation method in the view to enable client validation. In MVC3, this is no longer necessary because client validation is enabled by default. It can be turned off in web.config. In order for client-side validation to work, you still need to include references to jQuery and the jQuery.Validation library in your website, either by serving them on your own site or using a CDN server from Microsoft or Google. Remote Verification In the following example, the Remote tag specifies that the username field be validated through a method named UserNameAvailable defined in UsersController. Razor's syntax is simple and clear, requiring minimal typing.
The following code is defined in the controller
For more resources on the Remote attribute, refer to How to: Implement Remote Validation in ASP.NET MVC http://msdn.microsoft.com/en-us/library/gg508808(VS.98).aspx JSON binding support ValidationAttribute Class <br /> The ValidationAttribute class has been improved in .NET Framework 4 to support new IsValid overloads that provide more information about the current validation context, such as what object is being validated. This allows you to validate the current value based on other properties of the Model. For example, the new CompareAttribute allows you to compare the values of two properties of the Model. In the following example, the ComparePassword attribute must match the Password field to pass validation. Improvements to Model Validation
Verification interface The IValidatableObject interface allows you to perform model-level validation and allows you to provide validation error messages for the entire model state, or based on two properties of the model. When the model is bound, MVC3 receives error messages from IValidatableObject and when using the built-in HTML helpers in the view, the affected fields will be automatically identified or highlighted. The IClientValidatable interface allows ASP.NET MVC to discover supported client-side validators at runtime. This interface is used to support integration with different validation frameworks. For more information about validation interfaces, see the Model Validation Improvements section in Scott Guthrie's MVC 3 Preview blog post. Dependency Injection Improvements MVC3 supports the Common Service Locator library and any DI container that supports the IServiceLocator interface of this library. It also supports the new IDependencyResolver interface for easy integration into the DI framework. Other new features NuGet Integration NuGet allows developers maintaining open source projects, for example, like Moq Project, NHibernate, etc., to register them to an online website. For more information, see the NuGet documentation on the CodePlex site. Output caching for partial pages Granular control in request validation Expandable New Project dialog In MVC3, you can add project templates, view engines, and unit test project frameworks to the New Project dialog. Scaffolding improvements By default, create and edit scaffolds now use the Html.EditorFor helper instead of the Html.TextBoxFor helper. This improvement supports metadata tags in the model when generating a view in the Add View dialog. New Overloads for Html.LabelFor and Html.LabelForModel PDF has added new method overloads for LabelFor and LabelForModel that allow specifying or overriding the Label text. No Session Controller Support The new AdditionalMetadataAttributePDF class allows access to the ModelMetadata.AdditionalValues dictionary for a property of a Model through the AdditionalMetadataAttribute tag. For example, if a property of a model only supports administrator display, you can set it as follows: Controller (registering and injecting controller factories, injecting controllers). |
<<: Example analysis: Performance optimization of "Qichu Encyclopedia"
>>: ASP.NET MVC/C# development tips record.
As the Qingming Festival approaches, the local ep...
If we talk about the apps that consume the most m...
In 1937, Qian Sanqiang went to the University of ...
The mid-ocean ridge is 2000~3000m below the sea s...
"Is the epidemic coming again? Everything wa...
Pancreatic cancer, a malignant disease originatin...
This article was published in the Bulletin of the...
According to relevant media reports, the Wall Str...
In September 2021, the Tianjin Institute of Indus...
[51CTO.com original article] Memcached is a free,...
Typically, a hit H5 has three elements: I. Elemen...
[[413605]] The official version of iOS 14.7.1 has...
Produced by: Science Popularization China Author:...
Yesterday, the Ministry of Culture released the 2...
On Douban, a group called "We Love Health Pr...