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 was trying the do a new binder
Public Class SmartModelBinder
Inherits DefaultModelBinder
Protected Overrides Sub SetProperty(controllerContext As ControllerContext, bindingContext As ModelBindingContext, propertyDescriptor As System.ComponentModel.PropertyDescriptor, value As Object)
If propertyDescriptor.PropertyType Is GetType(Decimal) Or propertyDescriptor.PropertyType Is GetType(Decimal?) Then
If value Is Nothing Then
value = 0
End If
End If
MyBase.SetProperty(controllerContext, bindingContext, propertyDescriptor, value)
End Sub
End Class
But the value is already converted at this point
How can I extend the binder to get the string value from the form and perform a different transformation?
What about this?
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.