问题
I am using the VS 2012 RC and trying to follow the MVC4-tutorial from here:
http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/accessing-your-model%27s-data-from-a-controller
I get to "Enter some details about a movie and then click the Create button." and then get an error:
"The value '9.99' is not valid for Price."
So I figure it needs a decimal comma instead and try with 9,99 instead with the following results:
"The field Price must be a number."
So I do not know how to enter the number and satisfy the validation checks. There seem to be several. So I enter another number 9 (without any decimals or decimal character) and then it works.
I then press 'Edit' to see if I can now change the numbers. The price is now presented as
9,00
with a decimal comma, and the date as
01.11.1989 00:00:00
The following errors are then displayed immediately, after simply copying the date and price fields to the clipboard:
The field ReleaseDate must be a date.
and
The field Price must be a number.
and it is again impossible to save.
So I guess, ASP.NET MVC scaffolding automatically requires that numbers are formatted using culture invariant (decimal point) and using my (German) culture which requires decimal comma. It further requires dates to be formatted culture invariantly which I would guess is the US date format.
Then when displaying, it uses the current (German) culture by default.
I am unfortunately using a computer with German locale settings.
I would like the values to display using the current culture, which it already does. But I would also like the validators, of which there seem to be several, to accept any valid format, or at a minimum the format that is valid in the current culture.
What is the best solution for this for a real application (as opposed to the tutorial)?
回答1:
It turns out, the tutorial describes how to fix this later in the tutorial.
回答2:
You're more than likely using the Culture which is assumed by defualt from your PC's culture. You can declare a default culture if you like, ie us-EN.
See http://everymanprogrammer.com/index.php/asp-net-easily-make-your-web-application-multilingual-part-2/
来源:https://stackoverflow.com/questions/11985545/asp-net-mvc4-tutorial-scaffolding-validation-and-display-use-several-different