how to validate the field in mvc before ajax call

Solutions on MaxInterview for how to validate the field in mvc before ajax call by the best coders in the world

showing results for - "how to validate the field in mvc before ajax call"
Fabian
07 Mar 2018
1BY LOVE
2NOTE : In case of AJAX call on button
3
4•	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. 
5•	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.
6
7$('#btnCreateLocation').click(function (e)
8    {
9        var _this = $(this);
10        var _form = _this.closest("form");
11        if (!$(_form).data('unobtrusiveValidation').validate()) {
12            alert('NOT valid');
13        }
14        else {
15            alert('valid');
16            $('form').submit();
17        }
18        
19    });