views:

238

answers:

1

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?

A: 
//DefaultModelBinder.GetModelProperties    
var val = GetModelProperties(controllerContext,bindingContext)[item.Property];

How about this?

takepara