Decimal value is not valid for price. MVC3
10,637
I set in web.config
<system.web>
<globalization uiCulture="en-US" culture="en-US"/>
<system.web>
this solution worked for me, i was getting the same error
Author by
Joe Rakhimov
Updated on June 27, 2022Comments
-
Joe Rakhimov almost 2 years
Product.cs
... [Required(ErrorMessage="Price is required")] [Range(0.01, 100000.00, ErrorMessage="Price must be between 0.01 and 100000.00")] public decimal Price { get; set; } ...
When I enter '89.48', form is giving 'The value '89.48' is not valid for Price'. I think this is becuase of default language of my PC. It is not English. It is Russian.
I tried to solve this issue by haacked.com instructions:
- I have created Model class DecimalModelBinder and copied code from haacked.com into class
-
Updated Global.asax with
ModelBinders.Binders.Add(typeof(decimal), new DecimalModelBinder());
No effect. Then I tried to fix it by client-side validation 1.Added JavaScript file called "jQueryFixes.js" with code
$.validator.methods.range = function (value, element, param) { var globalizedValue = value.replace(",", "."); return this.optional(element) || (globalizedValue >= param[0] && globalizedValue <= param[1]); } $.validator.methods.number = function (value, element) { return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:[\s\.,]\d{3})+)(?:[\.,]\d+)?$/.test(value); }
This code did not solve this issue. Can you suggest what I am doing wrong here?
-
Suraj Rao about 7 yearsWhile this code snippet may solve the problem, it doesn't explain why or how it answers the question. Please include an explanation for your code, as that really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion.From Review
-
Moslem Hadi about 7 yearsWhat id we need another globalization??!!