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:
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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With