MVC Client Side Validation without preventing form submit
I have a form that allows the user to edit my model. They can save the data, as well as publish it. When the user hits save I want to go ahead and save the form even if its doesnt pass validation so that can come back and finish fillin开发者_JS百科g it out later. But if they blur out of a field and its required I still want it to turn red and show the error message. So basically I want normal client side validation without it preventing the form from posting.
Is there a way to do that?
simply override the form submit and that should disable the validation.
$(function () {
$("form").submit(function () {
if (!$(this).valid()) {
//form is not valid
return true;
}
});
});
You dont need the check there obviously and can just return true, thats just to show you how to check if its valid.
精彩评论