After posting the form with an input of type 'number' and value "1,5", the browser (Chrome 43.0.2357.130, FF 38.0.5) is sending the number with a dot as decimal separator, but the input has attribute lang="cs" (in Czech Republic we use decimal comma), so for ASP.NET MVC it's the incorrect format.
How can I set the browser (form/input) to send what user really filled ("1,5" in my case)?
The form data sent from the browser:
__RequestVerificationToken:KJG1yJxm-1EcUHPwgvr0gPpkyoEHHHcTfSu6hHvaKDA_XKHTzWfPfUJtAr11gNiR_euG_jWYmXlrMO7dyhSf7g4K74eOVTtEzLQ1OdrTLZ_cbIyyYj5vrgxlk81JzuhM0
PaymentMethodId:8
PaymentMethod:Direct payment
Provider:Direct payment
MinAmount:1,00000000
MaxAmount:5000,00000000
Amount:1.5
Oukey, it looks like I found workaround, but look at it as example how you can handle similar issue...
public class ApolloModelBinder : DefaultModelBinder
{
protected override void BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor)
{
var request = controllerContext.HttpContext.Request;
decimal i;
var value = request.Form[propertyDescriptor.Name];
if (propertyDescriptor.PropertyType == typeof(decimal) && decimal.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out i))
{
propertyDescriptor.SetValue(bindingContext.Model, i);
return;
}
base.BindProperty(controllerContext, bindingContext, propertyDescriptor);
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments