Your Weight property is of type double
, but you have created a model binder for the type decimal
.
Change your model binder to this:
public class DoubleModelBinder : DefaultModelBinder
{
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var valueResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
object actualValue = null;
try
{
actualValue = Convert.ToDouble(valueResult.AttemptedValue, CultureInfo.InvariantCulture);
}
catch (FormatException e)
{
bindingContext.ModelState.AddModelError(bindingContext.ModelName, e);
}
return actualValue;
}
}
And, in your Global.asax.cs
's Application_Start()
:
ModelBinders.Binders.Add(typeof(double), new DoubleModelBinder());
You don't need the EFModelBinderProvider
. You can just remove that.