Reputation: 57373
This used to work.
<AcceptVerbs(HttpVerbs.Post)> _
Function Widget(ByVal collection As FormCollection) As ActionResult
...
If ... Then
ModelState.AddModelError(...)
ModelState.SetModelValue("Gadget", collection.ToValueProvider("Gizmo"))
Return View()
End If
...
End Function
I upgraded to ASP.NET MVC 2 Beta and ASP.NET MVC 2 Futures Assembly for Beta and now ToValueProvider()
fails with this compile-time error:
Interface 'System.Web.Mvc.IValueProvider' cannot be indexed because it has no default property
How do I use ModelState.SetModelValue()
if not with collection.ToValueProvider()
?
Upvotes: 0
Views: 1158
Reputation: 1
I've done the following and it's working.
ModelState.SetModelValue("Gadget", ValueProvider.GetValue(ControllerContext, "Gizmo"));
Haven't tried to deploy it yet.
Upvotes: 0
Reputation: 15900
Extract taken from the ASP.NET MVC 2 Beta release notes:
Changes in ASP.NET MVC 2 Beta
Introduced the IValueProvider interface, which replaces all usages of IDictionary<string, ValueProviderResult>.
Every property or method argument that accepted IDictionary<string, ValueProviderResult> now accepts IValueProvider. This change affects only applications that include custom value providers or custom model binders.
Examples of properties and methods that are affected by this change include the following:
- The ValueProvider property of the ControllerBase and ModelBindingContext classes.
- The TryUpdateModel methods of the Controller class.
- New CSS classes were added in the Site.css file that are used to style validation messages.
HTHs,
Charles
Upvotes: 2
Reputation: 57373
Just remove the string parameter.
Wrong:
collection.ToValueProvider("Gizmo")
Correct:
collection.ToValueProvider()
Creates a new run-time error after published to web server:
Method not found: 'System.Web.Mvc.IValueProvider System.Web.Mvc.FormCollection.ToValueProvider()'.
Download and install .NET Framework 4 Beta 2 onto web server.
Microsoft Download Center: Microsoft .NET Framework 4 Beta 2
Upvotes: 0