mvc validation with ajax request code example

Example: How to validate the field in mvc before ajax call

BY LOVE
NOTE : In case of AJAX call on button

•	If HTML input type is Submit for the button, then Success event is not calling successfully. If Input type is button then Success event called successfully. 
	Just remove type="submit" from your button and let your jQuery ajax call be triggered first. Once you get the response then you can submit your form as well.

$('#btnCreateLocation').click(function (e)
    {
        var _this = $(this);
        var _form = _this.closest("form");
        if (!$(_form).data('unobtrusiveValidation').validate()) {
            alert('NOT valid');
        }
        else {
            alert('valid');
            $('form').submit();
        }
        
    });