Asp.Net MVC 2 Beta ModelBinder 更改
我正在尝试根据 MVC 2 Beta 中的 ValueProvider 重大更改来修改以下自定义模型绑定程序。
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);
}
问题是这一行总是返回为 null
BindingContext.ValueProvider.GetValue(controllerContext, item.Property)
有什么想法吗?
I am trying to modify the following custom model binder according to the ValueProvider breaking changes in 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
BindingContext.ValueProvider.GetValue(controllerContext, item.Property)
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个怎么样?
How about this?