Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Localizing validation messages at client side by jQuery in ASP.net MVC

I am using jquery for client side validation together with data annotations. Everything is working fine but I would like to localize a message when a non numeric value is entered in numeric textbox. For server side validation it can be done by setting DefaultModelBinder.ResourceClassKey to resource class name and providing value for PropertyValueInvalid key.

However for client side validation asp.net mvc is using it's own resource file with key 'ClientDataTypeModelValidatorProvider_FieldMustBeNumeric'. The only way to solve it that I found is described at Custom Server and Client Side Required Validator in MVC 2 using jQuery.validate. The solution does work but I was wondering if there is an easier or more correct way to do it.

Thanks.

like image 895
Giorgi Avatar asked Nov 14 '22 05:11

Giorgi


1 Answers

Maybe a bit more elegant way is to rewrite System.Web.Mvc.ClientDataTypeModelValidatorProvider class and replace it in ModelValidatorProviders.Providers collection.

See section Implicit Non-Numeric-Field problem in http://jwwishart.blogspot.com/2011/03/custom-server-and-client-side-required.html for more details.

like image 125
danijelk Avatar answered Dec 10 '22 23:12

danijelk