Link to home
Start Free TrialLog in
Avatar of praveen1981
praveen1981Flag for India

asked on

Form validation in mvc

Hi

I am doing client side validation in mvc4 razor

which is working fine, but i want to do an ajax call once

the form is valid,then it is not validating properly,

i am using following scripts


 <script src="~/Scripts/jquery-1.7.1.min.js"></script>
 <script src="~/Scripts/jquery.validate.js"></script>
 <script src="~/Scripts/jquery.validate.unobtrusive.js"></script>

 @using (Html.BeginForm("EmployeePost", "Employee", FormMethod.Post, new { id="frm"}))
 {
 // i have necessary controls and submit button as follows

   <input type="submit" value="submit" />
 
 }


 <script>
            $(function () {
                $('#frm').submit(function () {
                    if ($(this).valid()) {
                        alert('the form is valid');
                    // goes with ajax call
                    }
                    else {
                        alert('Invalid');
                    }
                });
            });
</script>

now here , if i don't enter required field values ,it is
giving me correct invalid message, but even after entering all

the required field values still it is giving invalid message,

i.e it is giving invalid message all the time, so, it is not

validating properly,

could you please suggest me what is the wrong in above code.

           Many thanks.
ASKER CERTIFIED SOLUTION
Avatar of praveen1981
praveen1981
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of praveen1981

ASKER

working fine