Solved

Form validation in mvc

Posted on 2014-01-21
2
307 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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 …
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 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