Disable validation for an element with jQuery Unobtrusive Validation

后端 未结 3 793
忘掉有多难
忘掉有多难 2020-12-14 11:05

I am generating a list of elements on a page, and they all have validators attached to them. When I look in the HTML source, I see something like:



        
相关标签:
3条回答
  • 2020-12-14 11:36

    I think this will help.

    <div class="editor-field">
           @{ Html.EnableClientValidation(false); }
           @Html.TextBoxFor(m => m.BatchId, new { @class = "k-textbox" })
           @{ Html.EnableClientValidation(true); }
    </div>
    
    0 讨论(0)
  • 2020-12-14 11:40

    This worked better for me:

    $('#Reference').rules('add', 'required');
    $('#Reference').rules('add', 'remove');
    $('#Reference').rules('add', { minlength: 2 });
    
    0 讨论(0)
  • 2020-12-14 11:49

    I actually found a solution that fits my needs better. I can do the following:

    $(function() {
        var settngs = $.data($('form')[0], 'validator').settings;
        settngs.ignore = ".ignore";
    });
    

    And with that i can 'toggle' any element that i want by adding or removing the classname ignore from an element.

    0 讨论(0)
提交回复
热议问题