MVC 3 decimal server side validation system

I use jQuery Unobtrusive confirmation ... I am configured with Globalize to accept numbers like this: 1.500.50 (Masked by JQuery)

My code is bye

1-) Customized Globalization

$.validator.methods.number = function (value, element) { return this.optional(element) || !isNaN(Globalize.parseFloat(value)); }; $(function () { Globalize.culture('pt-BR'); }); 

2-) Configured web.config

 <globalization culture="pt-BR" uiCulture="pt-BR" /> 

Ok, so I use the jQuery plugin to format Textbox to Money (PT-BR): 1.500.000.50 ...

My jquery client check works fine! But when it comes to server verification, I got a ModelState error:

 "The value '1.500.000,50' is not valid for Total." 

How can i fix this?

thanks

+6
source share
1 answer

There is a problem in associating MVC with such values. Take this post from Phil Haack. It shows you how to create a cusom model binding to handle this.

+7
source

Source: https://habr.com/ru/post/892250/


All Articles