My ASP.NET MVC4 application has a remote validation rule defined in model and implemented in a controller method. My form is dynamically added to the page. So, I used the following code to trigger the validation.
$(tabId).on("submit", formId, function (event) {
event.preventDefault();
var form = $(this);
form.removeData("validator");
$.validator.unobtrusive.parse(form);
if (form.valid())
{
// form submission
// THIS part executes even though the remote validation returns false
}
return false;
});
It starts remote validation and doesn't wait for the completion and then submits the form. If any other field is non-valid (say, name is a required field), then it stops the submission. However, it doesn't wait for the remote validation.
I found some work around on SO such as link1 and link2. However, these work only if I have jQuery validation rules defined in my page. However, I'm using MVC4 model validation rules. Thus I am not interested to redefine the rules in my view page again.
Any idea to solve?