ASP.NET 远程验证仅在模糊时? [英] ASP.NET Remote Validation only on blur?

查看:17
本文介绍了ASP.NET 远程验证仅在模糊时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 MVC 3 中使用远程验证,但它似乎在我输入某些内容时触发,如果这是该字段第二次处于活动状态.问题是我有一个自动完成框,所以他们可能会点击一个结果来填充该字段,MVC 将其视为离开"它.

I'm using the remote validation in MVC 3, but it seems to fire any time that I type something, if it's the second time that field's been active. The problem is that I have an autocomplete box, so they might click on a result to populate the field, which MVC views as "leaving" it.

即使除了自动完成的事情,我也不希望它在编写中途时尝试验证.有没有一种方法可以说仅在输入完成后 n 毫秒内运行验证"或仅在模糊时运行验证?"

Even apart from the autcomplete thing, I don't want it to attempt to validate when they're halfway through writing. Is there a way that I can say "only run validation n milliseconds after they are finished typing" or "only run validation on blur?"

推荐答案

MVC 3 依赖 jQuery Validation 插件进行客户端验证.您需要将插件配置为在启动时不进行验证.

MVC 3 relies on the jQuery Validation plugin for client side validation. You need to configure the plugin to not validate on key up.

您可以使用

$.validator.setDefaults({
   onkeyup: false
})

参见 http://docs.jquery.com/Plugins/Validation/Validator/setDefaults 和这里的 onkeyup 选项 http://docs.jquery.com/Plugins/Validation/验证.

See http://docs.jquery.com/Plugins/Validation/Validator/setDefaults and the onkeyup option here http://docs.jquery.com/Plugins/Validation/validate.

这篇关于ASP.NET 远程验证仅在模糊时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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