开发者

Interface 'System.Web.Mvc.IValueProvider' cannot be indexed because it has no default property

This used to work.

<AcceptVerbs(HttpVerbs.Post)> _
F开发者_如何学Pythonunction 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()?


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


Just remove the string parameter.

Wrong:

collection.ToValueProvider("Gizmo")

Correct:

collection.ToValueProvider()

Update

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


I've done the following and it's working.

ModelState.SetModelValue("Gadget", ValueProvider.GetValue(ControllerContext, "Gizmo"));

Haven't tried to deploy it yet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜