views:

56

answers:

1

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
Yes thats true.
Malcolm Frexner
So this should be working for me?
jcm
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
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