In my MVC project (which uses jQuery Unobtrusive Validation), I've got a view which contains multiple forms. I'd like to prevent all forms from submitting when they are valid, and do something else instead.
Here is a brief snippet of one of the forms:
@using (Html.BeginForm()
{
@Html.LabelFor(m => m.Name)
@Html.TextBoxFor(m => m.Name)
// etc.
In my Javascript validation configuration, I've included onsubmit: false
, ignore: []
, and a custom submitHandler
- but my forms are submitting anyway.
$.validator.setDefaults({
debug: false,
onsubmit: false,
ignore: [],
submitHandler: function (event) {
event.stopPropagation;
console.log("Form submission prevented.");
}
});
I've also tried something like this unsuccessfully:
$('form').each(function () {
$(this).validate({
debug: false,
onsubmit: false,
ignore: [],
submitHandler: function (event) {
event.stopPropagation;
console.log("Form submission prevented.");
}
})
});
Why are my forms still submitting?