2

I have a web site with different languages. Inside a model, I have the following member declaration:

[Required(ErrorMessageResourceType = typeof(ViewRes.GlobalResource), ErrorMessageResourceName = "awr1")]
[Range(typeof(decimal), "0.00100001", "10000", ErrorMessageResourceType = typeof(ViewRes.GlobalResource), ErrorMessageResourceName = "TotalMoneyMinMaxValidation")]
public decimal TotalMoney { get; set; }

When I change the UI culture to ru-RU, I get the following error:

0.00100001 is not a valid value for Decimal.

How can I keep my culture info and UI as ru-RU but have all decimals be a period(.) instead of a comma(,)?

Here's what I've tried:

CultureInfo ci = new CultureInfo("ru-RU");
ci.NumberFormat.NumberDecimalSeparator = ".";
Thread.CurrentThread.CurrentUICulture = ci;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ci.Name);

not working...

patridge
  • 26,385
  • 18
  • 89
  • 135
Haddar Macdasi
  • 3,477
  • 8
  • 37
  • 59

1 Answers1

1

There is no precise workaround for this issue since the RangeAttribute is converted using the run-time culture. You need to either accept a loss of precision using doubles:

[Range(0.01, 10000)]

or give up on using the RangeAttribute entirely.

See this link.

lukegravitt
  • 892
  • 4
  • 12