0

I have a TextBoxFor for representing currency and the decimal point for each currency will be varying according to currencies. So I need to pass decimal point for each currency from server side. This is what I tried -

Server Side
ViewBag.decimalplace = "2"; //this may vary 2 or 3  according to currencies

Client Side
@{ var regex = string.Format(@"^\d+,\d{{0,{0}}}$", ViewBag.decimalplace); }
@Html.TextBoxFor(model => model.SourceCurrencyValue, 
new { data_val_regex_pattern = regex, data_val_regex = "Error message" })

Unfortunately, this is not working. where I went wrong?

Sandy
  • 2,429
  • 7
  • 33
  • 63
  • You could validate it in the `Controller`. Count the decimals using this: http://stackoverflow.com/questions/13477689/find-number-of-decimal-places-in-decimal-value-regardless-of-culture and then update the `Model.IsValid` as neccessary. – Rosdi Kasim Jul 19 '15 at 09:18
  • @RosdiKasim, I dont need to count the decimal part as I'm already know it. I'm passing it to view through viewbag. – Sandy Jul 20 '15 at 08:05

0 Answers0