I've read a lot of blogposts about this subject, but I never saw the complete solution.
I've scaffolfed this default html (where bedrag is a Decimal):
<div class="editor-field">
@Html.EditorFor(model => model.Bedrag)
@Html.ValidationMessageFor(model => model.Bedrag)
</div>
This generates a comma for the decimal in the input control when the page is rendered, even when I put this in my web.config:
<globalization culture="en-US" uiCulture="en-US" />
or this one
<globalization culture="auto" uiCulture="auto" />
Then, the Jquery Validation plugin complains that I have a comma as decimal separator in my 'bedrag' input field (which has been put there by the @Html.EditorFor(model => model.Bedrag)
), which gives the error my input is not a number; it expects a dot as a decimal separator.
But, when I enter the number as this 12.90, the defaults modelbinder converts my input to 1290 (input times 100).
Then I created a custom modelbinder, and in that code, the currentculture is 'nl-NL', so not the 'en-US' from my web.config.
So now I'm wondering:
1 Do I still need a custom model binder in 2014?
2 Which culture is used when ASP.Net creates the value for @Html.ValidationMessageFor(model => model.Bedrag)
? (and why not the one from my web.config?)
3 How can I dynamicly set the culture to use for the @Html.ValidationMessageFor(model => model.Bedrag)
4 How can I dynamicly set the culture to use for the Jquery validation?
I've been out of ASP.Net MVC for a year, but can it be that in 2014 I still have these issues with decimal signs?