c# - Decimal validation (data annotation) -
c# - Decimal validation (data annotation) -
i want pass decimal value controller. utilize asp.net mvc knockout.js.
in view have:
@html.textboxfor(x => x.test, new { data_bind = "value: test", @class = "form-control" }) @html.validationmessagefor(x => x.test)
my viewmodel:
[required(errormessage = "error")] [range(0, int32.maxvalue)] public decimal test{ get; set; }
and can't pass e.g 1,5 (with comma) because mvc validation doesn't allow me, if pass 1.5 (with dot), controller doesn't have value (it passed 0), if pass 5 it's work. if turn off mvc validation , pass 1,5 (with comma) it's work.
do know how can solve problem ? pass value comma , dot.
this allow positive values , can pass in decimals. validates numbers, or without decimal places, , comma 1000 separators.
[regularexpression(@"^(((\d{1,3})(,\d{3})*)|(\d+))(.\d+)?$",errormessage = "error")] [range(0, int32.maxvalue)] public decimal test{ get; set; }
if want have @ other regular expressions related numbers, here.
c# asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 knockout.js
Comments
Post a Comment