Disable validation for an element with jQuery Unobtrusive Validation
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>
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.
I would add one more option without overriding unobtrusive validator defaults. As validation for specific element is controled by data-val
attribute, you can set it as data-val="false"
.
So for Razor helper, use:
@Html.TextBoxFor(model => Model.DateOfBirth, new { @class = "form-control", data_val = false })
and for new .net core syntax, use:
<input asp-for="DateOfBirth" class="form-control" data-val="false">