Answer the question
In order to leave comments, you need to log in
Fractional separator in ASP.MVC 3?
Hello. I encountered such a problem that if the value in the QueryString contains a fractional number, then it will be “binded” in the TextBox without regard to culture, for example, if there is a url test.com/?number=1.5, “1.5” will be substituted in instead of “1, 5". When submitting such a form, a FormatException will occur and we will get an error in the ModelState.
I have described more on Stakoverflow . As I understand it, it is impossible to set up culture-specific binding in Views from QueryString using MVC. There is still a difficulty that I cannot use JavaSrcipt.
If anyone came across and found a beautiful solution, tell me please.
Answer the question
In order to leave comments, you need to log in
Well, I see the simplest solution - to spread it into two parameters. It's real right?
The cultural issue seems very far-fetched. It is based on the outdated foreign principle of writing long numbers with a space separator. For example:
1,000,000.02 - a million and a few kopecks But seriously, who does this when filling out forms? If we are talking about the formation of a URI, it is probably not the best idea to somehow associate the appearance of the parameters with the culture.
In my projects, I once wrote a ModelBinder for decimal and decimal ?, in which commas turn into dots. It may not be the most elegant solution on the planet, but for fractional numbers it looks quite adequate. A sort of nailing with a screwdriver instead of a microscope.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question