如何在xVal中有条件地禁用客户端验证?

时间:2022-12-09 12:08:03

I am using xVal in a ASP.NET MVC project. One of the forms has two buttons and i want to disable the client side validation when one of the buttons is clicked. Is there a way to conditionally disable client side validation in xVal?

我在ASP.NET MVC项目中使用xVal。其中一个表单有两个按钮,我想在单击其中一个按钮时禁用客户端验证。有没有办法在xVal中有条件地禁用客户端验证?

2 个解决方案

#1


1  

Instead of disabling client side validation... we can have rules execution only when we need it with the help of JQuery validate method.

而不是禁用客户端验证......我们只有在需要JQuery验证方法的情况下才能执行规则。

For Example: On button click event upon which validation rules to be fired... apply jquery form validation...

例如:在按钮上单击要触发验证规则的事件...应用jquery表单验证...

$("#ButtonID").click(function() {
    var valid = $("#FormID");   // Form ID to be entered
    //var validDate = validateDate(f);
    var validForm = valid.validate().form();
    // Set delay for 500ms so that all ajax validations would complete.
    setTimeout(function() { $("#FormID").validate().form(); }, 500);    // Form ID to be entered
    validForm = valid.validate().form();

    if (validForm) {
        // Post form data to server
    }
});

#2


0  

Not sure about xVal in particular, but with an Asp.Net form you can do the following-

特别是对xVal不确定,但使用Asp.Net表单,您可以执行以下操作 -

<asp:Button id="IgnoreClientValidation" runat="server" Text="Ignore Client" EnableClientScript="False" />

#1


1  

Instead of disabling client side validation... we can have rules execution only when we need it with the help of JQuery validate method.

而不是禁用客户端验证......我们只有在需要JQuery验证方法的情况下才能执行规则。

For Example: On button click event upon which validation rules to be fired... apply jquery form validation...

例如:在按钮上单击要触发验证规则的事件...应用jquery表单验证...

$("#ButtonID").click(function() {
    var valid = $("#FormID");   // Form ID to be entered
    //var validDate = validateDate(f);
    var validForm = valid.validate().form();
    // Set delay for 500ms so that all ajax validations would complete.
    setTimeout(function() { $("#FormID").validate().form(); }, 500);    // Form ID to be entered
    validForm = valid.validate().form();

    if (validForm) {
        // Post form data to server
    }
});

#2


0  

Not sure about xVal in particular, but with an Asp.Net form you can do the following-

特别是对xVal不确定,但使用Asp.Net表单,您可以执行以下操作 -

<asp:Button id="IgnoreClientValidation" runat="server" Text="Ignore Client" EnableClientScript="False" />