prevent多形式MVC 3提交与验证 [英] Prevent multiple form submits in MVC 3 with validation

查看:127
本文介绍了prevent多形式MVC 3提交与验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有它的许多输入字段,部分验证的一种形式。我使用MVC 3的默认验证插件如果服务器响应速度很慢,用户可以点击提交另一个时间,这可能会导致意外的行为。如何prevent呢?我试过形式的.submit事件注入code,但即使验证失败引发此事件。

I have a form with many input fields on it, some with validation. I use the default validation plugin in MVC 3. If the server response is slow, the user may click to submit another time, which may cause undesired behavior. How to prevent this? I've tried injecting code in the .submit event of the form, but this event is raised even if the validation fails.

推荐答案

您可以检查验证是否成功并禁用提交按钮:

You could check whether validation succeeded and disable the submit button:

$(function () {
    $('form').submit(function () {
        if ($(this).valid()) {
            $('input[type="submit"]').attr('disabled', 'disabled');
        }
    });
});

这篇关于prevent多形式MVC 3提交与验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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