开发者

Cannot apply indexing with [] to an expression of type 'System.Web.Mvc.IValueProvider'

I am converting an ASP.NET MVC application to ASP.NET MVC 2, and I get the following error:

Cannot apply indexing with [] to an expression of type 'System.Web.Mvc.IValueProvider'

Here is the开发者_高级运维 code:

public static void AddRuleViolation(this ModelStateDictionary modelState,
                                    RuleViolation error, 
                                    FormCollection collection)
{
    modelState.AddModelError(error.PropertyName, error.ErrorMessage);
    modelState.SetModelValue(error.PropertyName, 
                             collection.ToValueProvider()[error.PropertyName]);
}

How can this be remedied?


The implementation changed between ASP.NET MVC 1 and 2 for IValueProvider.

Try using the GetValue() method instead of referencing it by index.

collection.ToValueProvider().GetValue(error.PropertyName)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜