views:

729

answers:

2

I'm working with the NerdDinner application trying to teach myself ASP.NET MVC. However, I have stumbled upon a problem with globalization, where my server presents floating point numbers with a comma as the decimal separator, but Virtual Earth map requires them with dots, which causes some problems.

I have already solved the issue with the mapping JavaScript in my views, but if I now try to post an edited dinner entry with dots as decimal separators the controller fails (throwing InvalidOperationException) when updating the model (in the UpdateModel() metod). I feel like I must set the proper culture somewhere in the controller as well, I tried it in OnActionExecuting() but that didn't help.

+1  A: 

Set this in your web.config

<globalization uiCulture="en" culture="en-US" />

You appear to be using a server that is setup with a language that uses comma's instead of decimal places. You can adjust the culture to one that uses the comma's in a way that your application is designed, such as en-US.

Nick Berardi
I already have this, for some reason it does not work.
Pawel Krakowiak
what about the headers in your aspx page? Do any of them have anything set for culture?
Nick Berardi
@Nick: Nope, there's no custom stuff in there.
Pawel Krakowiak
Don't know what to tell you it is working for me.
Nick Berardi
Have you tried changing the culture for your browser?
Nick Berardi
A: 

Can you parse the text using the invariant culture - sorry, I don't have the NerdDinner code in fornt of me, but if you are passing in dot-separated decimals than the parsing should be OK if you tell it to use the invariant culture. E.g.

 float i = float.Parse("0.1", CultureInfo.InvariantCulture);

Edit. I suspect that this is a bug in the NerdDinner code by the way, along the same lines as your previous problem.

Steve Haigh
No, I'm not touching any properties. It is supposed to happen "magically" in UpdateModel(), but it throws a not so helpful exception without details. There are two problems - when presenting data from the model I need dots, because tha mapping JS will break, however when putting data back into the model I need commas this time, because otherwise the controller breaks.It's all a little weird and I'm not sure how to solve it, Google didn't help, neither did SO. :(
Pawel Krakowiak
Yes, I don't think you can solve it without changing the code. I have the ND code and I'll take a look sometime and try to verify this and send you a fix if I can, but I'm afraid it won't be soon as a have to work:-)
Steve Haigh
OK, I think you need to undo the change you made in your other question, I have posted a suggestion there on how to fix the issue and hopefuly my fix will not cause the side effect you are seeing here.
Steve Haigh
And then you need to take a look at http://stackoverflow.com/questions/528545/mvc-datetime-binding-with-incorrect-date-format to see how dates work (or otherwise) in MVC...
Steve Haigh