Validating form in mvc3 modal dialog window
-
03-12-2019 - |
Question
I am using mvc3 with the KendoUI window control to open up a partial view in a modal window.
I have a form with the popup that I am trying to validate before sending the form back to the server.
I have a click event on my main view that looks like
$("#submit-campaign").live("click",function () {
var form = $("#Send");
$.validator.unobtrusive.parse($(form));
form.validate();
if (form.valid()) {
console.log("valid");
} else {
console.log("invalid");
}
});
However its always been returned as true even if I haven't added values to some of the required.
I have referenced the 3 javascript files like
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
What do I need to do so I am getting the actual validation state clientside from the popup?
La solution
The correct way to check validation would be.
$("#submit-campaign").live("click",function () {
var form = $("#Send");
$.validator.unobtrusive.parse($(form));
var val = form.validate();
if (val.valid()) {
console.log("valid");
} else {
console.log("invalid");
}
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow