I want to expand the default model binding to be smarter when dealing with numbers. By default, it works very poorly when the game has commas and decimal points.
I tried to make 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 moment
How can I extend a binder to get a string value from a form and perform another conversion?
source
share