I want to extend the default model binding to be more smart when dealing with numbers. The default works very bad when are commas and decimals points in the game.
I
What about this?
ModelBinders.Binders.Add(typeof(decimal), new DecimalModelBinder())
And a custom binder. I guess I don't know if you can override decimal binding in this way, but it works for my own types.
public class DecimalModelBinder : DefaultModelBinder
{
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var valueProviderResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
if (valueProviderResult == null)
{
return base.BindModel(controllerContext, bindingContext);
}
// to-do: your parsing (get the text value from valueProviderResult.AttemptedValue)
return parsedDecimal;
}
}