Archive for 2009-07

Custom model binder to avoid decimal separator problems


I bumped into an issue while trying to get the open source ASP.NET MVC project NerdDinner running on my laptop. The Create action in the DinnersController just wouldn’t work. This was due to Latitude and Longitude values being set with a different decimal separator than my server expected. It got "0.0" instead of "0,0" which the Double.parse function didn’t understand. A client-side JavaScript wrote these values into hidden fields, so it was a bit difficult for me to understand at first. I wrote a custom model binder to solve this for all fields of type double at once.

As I’m still learning ASP.NET MVC, my solution may not be the optimal one.