I have to implement client side validation with click event for ajax posts. I followed the below url:
Call MVC 3 Client Side Validation Manually for ajax posts
I tried using this :
$('#buttonId').click(function(evt) {
evt.preventDefault();
var $form = $('form');
if($form.valid()) {
//Ajax call here
}
});
But the problem here is now the validation is working if there is invalid data. But if I give proper input also, the page is reloading and blank page is coming as a result.
I tried replacing evt.preventDefault() with return false. But there the validation is not working. Can anyone help me to solve this.
The thing is if drop down is not chosen, the validation message is coming. But If I give correct input, then output is not displayed.The page is refreshing.
I guess the problem is evt.preventDefault() . But validation is not working without this
buttonId, is a normal HTML button or is it a input typesubmitelement? if it is a submit type then yes your form will get submitted the HTML form way hence reloading the pagereturn false;needs to be the last line in the script