Solved

Form validation in mvc

Posted on 2014-01-21
2
302 Views
Last Modified: 2014-01-24
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.
0
Comment
Question by:praveen1981
  • 2
2 Comments
 

Accepted Solution

by:
praveen1981 earned 0 total points
ID: 39799237
Hi

I found  the problem,

Actually I have EmployeeId which is integer type in the model class

even though it is not decorated with required field attribute

as it is not nullable type , it is expecting the value

so, the form is not validating.
0
 

Author Closing Comment

by:praveen1981
ID: 39806109
working fine
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now