简体   繁体   English

我有一个输入类型为提交的按钮,想要使用MVC jQuery验证表单

[英]I have a button having input type submit want to validate the form using MVC jquery

In my MVC4 application I have a input type submit button but I am preventing it's nature , e.preventDefault () in my jquery and making an AJAX POST call 在我的MVC4应用程序中,我有一个输入类型的提交按钮,但我在jquery中阻止了它的本质e.preventDefault ()并进行了AJAX POST调用

('#submit').click(function(e){})

I want to validate whole form for required values before this call, and then only proceed further .. 我想在此调用之前验证整个表单的必需值,然后再继续进行..

I am able to do this if I do not use this function ('#submit').click(function(e){}); 如果我不使用此功能,则可以执行此操作('#submit').click(function(e){}); ie. 即。 by using simple input submit button the form getting validated automatically by jquery , 通过使用简单的输入提交按钮,表单将由jquery自动验证,

How can I use same functionality. 如何使用相同的功能。 in this case where I am making ajax call on submit button. 在这种情况下,我在“提交”按钮上进行了ajax调用。 I used this but it not working!! 我用了这个但是没用!

$("#userform").validate();
$("#userform").valid()

Assuming you have jquery.unobtrusive and jquery.validate loaded then: 假设您已加载jquery.unobtrusive和jquery.validate,则:

   $("#registerUserForm").submit(function () {
            if ($(this).valid()) {
                $.OverWatch.worker.postUserData(this.action, $(this).serialize(), function (data) {
                 //callback
                })
            }

            return false;
        })

    postUserData: function (url, data, callback) {

        $.LoadingOverlay("show");
        $.ajax({
            url: url,
            type: 'POST',
            data: data,
            success: function (data) {

                if (callback) {
                    callback(data);
                    $.LoadingOverlay("hide");
                }

            },
            error: function (event, jqxhr, settings, thrownError) {
                $.LoadingOverlay("hide");
            }
        });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将输入类型“按钮”更改为“提交按钮”以验证php表单 - Changing input type “Button” to “Submit Button” to validate php form 我想通过输入类型按钮检查表单验证,而不是通过提交,可以在这有任何帮助吗? - i want to check form validation by input type button, not by submit, could any one help in this? 表单提交使用带有按钮类型的jquery ajax而不是提交类型 - form submit using jquery ajax with button type not submit type 在JSP页面中使用jquery使用一个提交按钮来验证两个表单 - Validate two form with one submit button using jquery in JSP Page 如何使用jquery验证输入文件类型onclick提交? - How to validate input file type onclick submit using jquery? 我必须在IE中使用jquery框架两次按提交按钮提交表单 - I have to press submit button twice in IE using jquery framework to submit form 我希望锚点的行为类似于输入类型提交按钮 - i want a anchor should act like and input type submit button 在应用程序组件中提交按钮,并在其他组件中输入。 我应该如何验证我的表单“提交”按钮? - submit button in app component and input in the other component. How should I validate my form On submit button? 使用“共享”按钮(而不是“提交”类型的输入元素)时,如何使表单验证起作用? - How can I get Form Validation to work when using a “shared” button (instead of an input element of type “submit”)? 我必须在 jquery 按钮上单击两次才能提交注册表 - I have to click twice on a jquery button to submit a registeration form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM