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

一世执手 提交于 2019-12-03 07:54:28

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/4333125/localizing-validation-messages-at-client-side-by-jquery-in-asp-net-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!