New Features
This section describes features that have been introduced in the ASP. net mvc 2 beta release.
New renderaction Method
Html. renderaction(And its counterpartHtml. Action) Is an HTML helper method that callinto an action method from within a view and renders the output of the Action Method in place.Html. renderactionWrites directly to the response, whereasHtml. ActionReturns a string with the output.RenderactionWorks only with actions that render views.
Stronugly typed UI helpers
ASP. net mvc 2 between des new expression-based versions of existing HTML helper methods. The new helpers include the following:
·Validationmessagefor
·Textareafor
·Textboxfor
·Hiddenfor
·Dropdownlistfor
Tempdatadictionary improvements
the behavior of the tempdatadictionary class has been changed slightly to address scenarios where temp data was either removed prematurely or persisted longer than necessary. for example, in cases where temp data was read in the same request in which it was set, the temp data was persisting for the next request even though the intent was to remove it. in other cases, temp data was not persisted into SS multiple consecutive redirects.
To address these scenarios,Tempdatadictionary Class was changed so that all the keys keep ve indefinitely until the key is read fromTempdatadictionaryObject.KeepMethod was addedTempdatadictionaryTo let you indicate that the value shocould not be removed after reading.RedirecttoactionresultIs an example whereKeepMethod is called in order to retain all the keys for the next request.
Client validation Library
Microsoftmvcajax. Js now has des a client-side validation library that is used to provide client validation for models in ASP. net mvc. To enable client validation, include the following two scripts in your view.
·Microsoftajax. js
·Microsoftmvcajax. js
The following example shows a view with client validation enabled.
<Script Type= "Text/JavaScript"SRC= "Microsoftajax. js"> </Script>
<Script Type= "Text/JavaScript"SRC= "Microsoftmvcajax. js"> </Script>
<%Html. enableclientvalidation ();%>
<%Using (html. beginform ()){%
//...
<%}%>
"Add area" dialog box
ASP. net mvc 2 beta shortdes a newAdd AreaContext menu item when you right-click either the root project node or the areas folder (if one exists ). if a root areas Folder does not already exist, the command creates one, and it then creates the files and folders for the area that you specify.
Calling action Methods Asynchronously
TheAsynccontroller Class is a base class for controllers that enables action methods to be called asynchronously. this lets an action method call external services such as a web service without blocking the current thread. for more information, see using an asynchronous controller in ASP. net MVC in the ASP. net MVC 2 documentation.
Blank Project template
In response to customer feedback, an empty ASP. net MVC Project template is now supported with ASP. net MVC 2 beta. this empty project template contains a minimal set of files used to build a new ASP. net MVC project.
Multiple Model validator providers
ASP. net mvc 2 beta lets you register Multiple Validation providers. The following example shows how to register multiple providers.
Protected VoidApplication_start (){
Modelvalidatorproviders. Providers. Add (NewMyxmlmodelvalidatorprovider ());
Modelvalidatorproviders. Providers. Add (NewMydbmodelvalidatorprovider ());
//...
}
Multiple Value provider Registration
In ASP. net MVC 2 beta, the single value provider that was available in ASP. net MVC 1.0 has been split into multiple value providers, one for each source of request data. the new value providers include the following:
·Formvalueprovider
·Routedatavalueprovider
·Querystringvalueprovider
·Httpfilecollectionvalueprovider
These value providers are registered by default. You can register additional value providers that pull data from other sources. The following example shows how to register additional value providers in the in global. asax file.
Protected VoidApplication_start (){
Valueproviders. Providers. Add (NewJsonvalueprovider ());
//...
}
Other improvements
The following additional changes have been made to existing types and members for ASP. net mvc 2 beta.
·The build task for multi-project areas has been removed and placed in the ASP. net mvc ures project.
·A newGetdisplaynameMethod was added toModelmetadataClass.
·A newIscomplextypeProperty was added toModelmetadataClass.
·Default Object Templates display only top-level properties of a model and do not attempt to recursively Display Properties of the properties of the model.
·Viewdatadictionary <t>Now allows value types forModelProperty.
·A newHidesurroundinghtmlProperty was added toModelmetadataClass. This is used to indicate that the HTML "Chrome" surrounding a field in a template shocould not be displayed.
·Templated helpers now supportByte []AndSystem. LINQ. BinaryProperties on the model. WhenHiddeninputUi hint attribute is applied to properties of these types, the editor template will base-64-encode the value of these properties in a hiddenInputElement.
·A newAdditionalvaluesDictionary property was added toModelmetadataClass.
·A newRoutelink Method overload was added that requires only two parameters, link text and the route name.
·A new protected virtualCreatetempdataproviderMethod was added toController Class. This allows you to supply a custom derivedTempdataproviderObject by overriding that method.
·When the model is binding to a collection,Defaultmodelbinder Object no longer requires collection indexes to be an unbroken ascending sequence of positive integers.
·A newAjax. EscapeMethod was added that lets you escape JavaScript strings.
·The default templates forDecimalType now format values to two decimal places.
·GenerateurlIs now a public methodUrlhelper.
·TheAccountcontroller Class in the default template was updated to make use of the template helpers and data annotations.
·Modified the default T4 templates for the add view dialog to emit expression based helpers. also removed the validation summary.
: Asp.net MVC beta download