在客户端的jQuery在ASP.net MVC本地化验证消息 [英] Localizing validation messages at client side by jQuery in ASP.net MVC

查看:89
本文介绍了在客户端的jQuery在ASP.net MVC本地化验证消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用客户端验证的jQuery连同数据​​注解。一切工作正常,但我想当数字文本框中输入一个非数字值本地化的消息。对于服务器端验证,可以通过设置DefaultModelBinder.ResourceClassKey资源类名和PropertyValueInvalid密钥提供值来完成。

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.

不过,对于客户端验证asp.net mvc的是利用它与密钥自身的资源文件'ClientDataTypeModelValidatorProvider_FieldMustBeNumeric。解决这个问题的唯一办法,我发现在<一个被描述href=\"http://jwwishart.word$p$pss.com/2010/03/22/custom-server-and-client-side-required-validator-in-mvc-2-using-jquery-validate/\"相对=nofollow>自定义服务器和客户端验证所需的MVC 2使用jQuery.validate 。该解决方案的工作,但我不知道是否有一个更容易或更正确的方式来做到这一点。

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.

感谢。

推荐答案

也许有点多优雅的方式是重写 System.Web.Mvc.ClientDataTypeModelValidatorProvider 类和替换在 ModelValidatorProviders.Providers 集合。

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

见的隐非数字场问题的的=htt​​p://jwwishart.blogspot.com/2011/03/custom-server-and-client-side-required html的相对=nofollow> http://jwwishart.blogspot.com/2011/03/custom-server-and-client-side-required.html 了解更多详情。

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

这篇关于在客户端的jQuery在ASP.net MVC本地化验证消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆