[英]Asp.Net MVC 2 Beta ModelBinder Change
I am trying to modify the following custom model binder according to the ValueProvider breaking changes in MVC 2 Beta. 我试图根据ValueProvider打破以下MVC 2 Beta中的更改来修改以下自定义模型联编程序。
protected override void OnModelUpdated(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var obj = bindingContext.Model as Core.BusinessBase;
if (obj != null)
{
var errors = from r in obj.BrokenRulesCollection
where r.Severity == Validation.RuleSeverity.Error
select r;
foreach (var item in errors)
{
bindingContext.ModelState.AddModelError(item.Property, item.Description);
//Was -> bindingContext.ModelState.SetModelValue(item.Property, bindingContext.ValueProvider[item.Property]);
bindingContext.ModelState.SetModelValue(item.Property, bindingContext.ValueProvider.GetValue(controllerContext, item.Property));
}
}
else
base.OnModelUpdated(controllerContext, bindingContext);
}
The problem is this line always comes back as null 问题是此行总是返回null
BindingContext.ValueProvider.GetValue(controllerContext, item.Property)
Any ideas? 有任何想法吗?
//DefaultModelBinder.GetModelProperties
var val = GetModelProperties(controllerContext,bindingContext)[item.Property];
How about this? 这个怎么样?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.