How is formatted user input typically handled in an MVC application? A user entering "1,000.00" for a number for example. I'm somewhat surprised the default ModelBinder does not pick up on this. Would this be the type of thing I would create my own ModelBinder for?
+2
A:
I think that DefaultModelBinder use CultureInfo.CurrentCulture to parse numeric data.
PanJanek
2009-12-10 18:40:25
Yes thats true.
Malcolm Frexner
2009-12-10 22:13:16
So this should be working for me?
jcm
2009-12-10 23:11:14
It depends on the CurrentCulture of your app. You can check it or chage it by changing the property System.Threading.Thread.CurrentThread.CurrentCulture. For example: if the culture is en-US, then value like 9,876,543,210,987,654.3210 should be properly parsed to Double or Decimal value 9876543210987654.3210.
PanJanek
2009-12-11 06:46:41
I think the value is not parsed. It is converted. (ValueProviderResult -> ConvertSimpleType in the MVC source). The last time I had some problems with decimal this realy made a difference. See TypeConverter Class in http://msdn.microsoft.com/en-us/library/system.componentmodel.typeconverter.aspx
Malcolm Frexner
2009-12-11 14:17:50