事件挂钩MVC不显眼远程验证 [英] Event hooks for MVC unobtrusive remote validation

查看:141
本文介绍了事件挂钩MVC不显眼远程验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法挂接到客户端上不显眼的MVC3远程验证,数据提交到远程方法之前,并从远程方法返回的结果后?

Is there a way to hook into MVC3 unobtrusive remote validation on the client, before data is submitted to the remote method, and after a result is returned from the remote method?

我想讲一个远程验证程序只有在点击提交按钮执行验证。正常行为是在关键preSS验证了几次,比如,模糊等,这是不行的,因为有问题的验证方法需要调用一个非幂等操作。我需要确保,如果用户点击了提交按钮的方法时才会激活。

I am trying to tell a remote validator to only perform validation if the submit button is clicked. The normal behavior is to validate several times, such as during keypress, blur etc. This is no good, as the validation method in question needs to call a non-idempotent operation. I need to make sure that method is only invoked if the user has clicked the submit button.

如果我能钩到一个活动之前,我可以作为被点击或不是标志提交按钮的形式设置字段。不过,我需要远程方法返回一个验证结果后重置该标志。

If I could hook into a before event, I could set a field in the form that flags the submit button as being clicked or not. However I would need to reset this flag after the remote method returns a validation result.

任何其他建议?这是用来验证使用ASP.NET成员资格提供程序的 Membership.ValidateUser(用户名字符串,字符串密码)方法的密码。这种方法将增加 FailedPasswordAttemtCount 每一个无效的密码发送时间,所以我不希望它模糊,关键preSS等过程中执行

Any other suggestions? This is for validating a password using the ASP.NET Membership Provider's Membership.ValidateUser(string username, string password) method. This method will increment the FailedPasswordAttemtCount each time an invalid password is sent, so I don't want it to execute during blur, keypress, etc.

推荐答案

您可以覆盖默认验证选项当前页面:

You could override the default validation options for the current page:

$.validator.setDefaults({
    onkeyup: false,
    onfocusout: false,
    onsubmit: true
});

这篇关于事件挂钩MVC不显眼远程验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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