ASP. net mvc codeplex preview 5 update details
This document describes the changes between ASP. net mvc framework between the codeplex preview5 (P5) and preview4. It also explains how to change the existing MVC application to adapt to these changes.
What's new?
This time, P5 is still a temporary version. It includes some new features and performance improvements. The ASP. Net MVC group wants to collect feedback from the community as usual. If you have any suggestions or comments, please feel free to go to (http://forums.asp.net/1146.aspx) for feedback.
Note: before you install P5, make sure that any previous versions of ASP. net mvc preview have been uninstalled. Disable all running instances of Visual Studio 2008.
The new features and Related Information provided in this update are as follows:
Viewengine Improvement
- Added global registration of view Engines. It is no longer the Controller's responsibility to determine which view engine to use to render a view (though the controller can still select a view engine if needed ). instead, when a controller wants to render a view, it returnsViewresultObject (viaViewMethod ).
- Added the global view registration engine function.The Controller is no longer responsible for deciding which view engine to use to present the view (you can still select the view engine in the controller when you really need it ). When the controller needs to present a view, it returns a viewresult object (through the view method ).
By default, this viewresult calls compositeviewengine to find a view. Compositeviewengine traverses the view engine from the static set of viewengines. Engines inherited from iviewengine to determine which view engine is used to present a specific view. The first compliant engine returns an iview instance to present the view.
- The renderpartial method is added to the iviewengine interface.The view engine now provides the concept of rendering some views. This is to work with the Helper method of HTML. renderpartial.
Helper Improvement
- Added support for rendering partial views.You have several options for passing View data to the partial view. The partial view can be renderedA different view EngineThan the containing view. usage is <% html. renderpartial (...); %>. This method does not return a string, but instead renders to the underlying response's suppliedTextwriterInstance.
- Provides support for rendering some views.Many people want to transmit data to some views. Some views can be displayed in various view engines through <% html. renderpartial (...); %>. This method does not return a string but presents a more underlying textwriter instance.
- Added a parameter to specify a default option label for dropdownlist controls.Specifying a value forOptionlabelArgument
- Added a parameter for the dropdownlist control to set the default options.This allows you to specify a default option for the dropdownlist method. The value of this default option is an empty string, and the specific content displayed depends on the parameters you provide. In this way, the default option of the drop-Drow list control that is provided with this parameter does not have a valid value. It exists only to provide some options.
- Organize the ASP. NET Ajax extension method to a new namespace.This allows you to easily complete Ajax helper extension in your code.
Note:If you have not seen these methods in upgrading your project from P4 to P5, introduce system in your application. web. MVC. the Ajax namespace is switched to the Web. add the highlighted content below to the config file.
<Namespaces>
<Add namespace = "system. Web. MVC"/>
<Add namespace = "system. Web. MVC. Ajax"/>
<Add namespace = "Microsoft. Web. MVC"/>
<Add namespace = "system. Web. Routing"/>
<Add namespace = "system. LINQ"/>
<Add namespace = "system. Collections. Generic"/>
</Namespaces>
- Added helpers for radiobutton and textarea controls and made overall improvements to other helpers.Improvements and changes to varous helpers have been made. In some cases, overloads have been added or removed to avoid overload ambiguity. (see next point .)
- Added the radiobutton and textarea controls in helper, and made a lot of modifications to Other helper.. We have made many changes or improvements to helper, and added or removed some reloads to avoid ambiguous reloads. (See the next one)
- To avoid ambiguity, we removed some reloads of the Helper method.We removed some overload for many helper methods and changed the value parameter from the object type to the string type. This is to avoid injection. If you call HTML. hidden ("name", 123) and want its value to be "123" but is accepted as an object by some reloads with incorrect HTML attributes. (Because 123 is an object)
Improvements to controller and filter
- Array support is provided for parameters of the Action method.Element data with the same name can be converted into an array and passed to the action method. For example, if you have three form objects (Let's Talk About textbox) called "color" and have different color names as values, when your form is submitted to action and the Action method has a string parameter of "color", their values are automatically organized into an array named color.
- The actionmethod attribute is removed from the action filter context object.This allows us to minimize coupling of public APIs.
- Provides support for custom model binder. Custom binder allows you to define a composite data type as a parameter of the Action method. To use this feature, Mark [modelbinder (...)] for complex data types or parameters.
- Added an iactioninvoker interface.The Controller class no longer depends on a clear controlleractioninvoker class. Now it inherits the iactioninvoker interface. This open behavior will have a profound impact on future expansion.
- AddedUpdatemodeMethod to the Controller class.Added an updatemode method for the Controller class. This method is used to update the attribute values provided by the HTTP protocol or route data in the model. When you update a model in the view, submit the value of the method can be used to update the property values of a model object based on either the values posted in the HTTP request or on Route data. when you attempt to update the model, errors that occur when the post values are converted to the property type are recorded in the newModelstatedictionaryInstance, which stores information about the model.
- ChangedHandleerrorattributeSo that it does not handle exceptions whenHttpcontext. iscustomerrorenabledIs false.This allows exceptions to propagate to the standard ASP. net error page (the "Yellow screen of death") during development, which provides you with more information than error page that is intended for users. for more information, see Eilon Lipton's blog post "httpcontext. iscustomerrorenabled-one of ASP. net's hidden gems ".
- Added a newAcceptverbsAttribute.This Attribute allows you to specify which HTTP verbs an action method will handle. if the current request's HTTP method does not match the list of verbs that are specified in the attribute, from the perspective of the Action invoker, The method does not exist. this allows you to have two action methods of the same name, as long as they respond to different HTTP verbs. this attribute inherits from the abstractActionselectionattributeClass, which can be used to control how action methods are chosen to respond to a request.
- Added a newActionnameAttribute.This Attribute allows you to assign an action name to a method. By default, if a method does not have this attribute applied, the method name itself serves as the action name.
For example, you can map a method named viewname to respond to the action view. This attribute andAcceptverbsAttribute can be used together, as shown in the following example:
[Acceptverb ("get")]
Public actionresult myaction (...);
[Actionname ("myaction"), acceptverb ("Post")]
Public actionresult myaction_formsubmit (...);
[Acceptverb ("get")]
Public actionresult otheractionoverloaded (string ID );
[Acceptverb ("Post")]
Public actionresult otheractionoverloaded (string ID ,...);
A GET request for/controller/myaction is handled by the first method, while a POST request for/controller/myaction is handled by the second method.
Likewise, even though the Code contains two methods named otheractionoverloaded, which is normally not allowed for actions, a GET request for/controller/otheractionoverloaded only matches one of those methods (due toAcceptverbsattribute) And no exception is thrown. a POST request for the same URL matches the second otheractionoverloaded method.
Known issues and breaking changescontrollers
The abstractControllerClass now derives fromControllerbase, Which contains useful properties suchViewdataAndTempdata. Additionally,Controllercontext. ControllerProperty isControllerbaseReference ratherIcontrollerReference. This change was made so that filters can accessViewdataAndTempdataInstances without castingControlllercontext. ControllerProperty.
To support this change, the protectedController. Execute (controllercontext)Method was removed. If you have a custom controller that overridesExecute (controllercontext)Method, change it to overrideExecutecoreMethod instead.
Controllers that require additional initialization steps to perform tasks such as setting the thread culture or assigning a custom providerTempdataCan do so by overridingInitialize (requestcontext)Method. The implementation in the base class ensures thatControllercontextProperty will be set.
View Engines
We changed the iviewengine interface. Now, when he finds the view, he does not present them.
Helper Methods
We have eliminated some methods to overload helper. This may cause problems in your existing view after the upgrade. At the same time, the namespace of the ASP. NET Ajax helper method has been reorganized. For more information, see the preceding section.
Visual Studio 2008 Service Pack 1 Beta Release
This version of ASP. net mvc cannot be applied to Visual Studio 2008 SP1 beta. If you use P5 in Visual Studio 2008, make sure that your Visual Studio 2008 has been upgraded to SP1 RTM.
Visual Studio 2008 express Edition Service Pack 1
Similarly, if you are using Visual Studio 2008 Express, you also need to upgrade it to SP1
You can get SP1 at the following address:
Http://www.microsoft.com/express/download/
You can also get more information from Scott Guthrie's blog post ASP. net mvc support with Visual Web Developer 2008 Express.
Upgrade from preview 4 to preview 5
· Rereference the following new P5 assembly:
·System. Web. Export actions. dll
·System. Web. Routing. dll
·System. Web. MVC. dll
By default, these assemblies are located in the % ProgramFiles % "Microsoft ASP. NET" ASP. net mvc codeplex preview 5 folder.
· Because system. web. abstractions and system. web. the version number of the routing assembly has been reduced to 3.5.0.0 (in ASP. net 3.5 SP1 provides accurate binary copies of these sets), you must change the web. config file to adapt to the upgrade. Find the following snippet in the web. config file:
System. Web. Routing, version = 0.0.0.0
Replace it with the following string:
System. Web. Routing, version = 3.5.0.0
Search for the following string:
System. Web. Category actions, version = 0.0.0.0
Replace it with the following string:
System. Web. Category actions, version = 3.5.0.0
· After this is done, recompile your application and solve other compilation problems. Most of the problems should be caused by the changes described above.