?
Solved

Form validation in mvc

Posted on 2014-01-21
2
Medium Priority
?
309 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

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.…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

762 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