Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Form validation in mvc

Posted on 2014-01-21
2
Medium Priority
?
311 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

610 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