1

I am a beginner with Jquery and asp MVC4 I use the Jquery validate plugin

 <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.js" type="text/javascript"> 

the code

<script> jQuery(document).ready(function() { jQuery("#monFormulaire").validate({ rules: { "reclamation": { "required": true, "minlength": 4, "maxlength": 60000 }, "cause": { "required": true, "minlength": 4, "maxlength": 60000 }, "curative": { "required": true, "minlength": 4, "maxlength": 60000 }, "Closing_date": { "required": true, "minlength": 1, "maxlength": 60000 } }, submitHandler: function (form) { /* envoyer Mail*/ mailJob(); } }); }); 

 <button type="submit" value="Page5" name="btnPage1" style="margin-left:1%" class="backRow" ></button> <table border="1" class="mytab" style="margin: auto;"> formulaire . </table> </form> 

The validation runs in the right way but the Action in the server side is not invoked anyone have any Idea ???

5
  • We would need to see your code to diagnose the problem.CommentedOct 25, 2013 at 15:22
  • The action on the server side won't be invoked until you've passed client-side validation.
    – ED-209
    CommentedOct 25, 2013 at 15:23
  • the validation in the client side work fine submitHandler: function (form) { /* envoyer Mail*/ mailJob(); } this function is invoked but only server side is not invokedCommentedOct 25, 2013 at 15:33
  • @slatniawadii and when you've filled in your form correctly, and client-side validation is passed, what happens then?
    – ED-209
    CommentedOct 25, 2013 at 15:36
  • nothing but when I remove the script of validation all run ok I think it is prob of this bad plugin I will try to develop my ownCommentedOct 25, 2013 at 15:41

3 Answers 3

1

The action on the server side won't be invoked until you've passed client-side validation

1
  • yes I know I am sorry for not giving you alot of details because it's not my code I just try to repaire it it is full of errors but in this code all run good when I move this code submitHandler: function (form) { /* envoyer Mail*/ mailJob(); } I add it just to run a javascript fuction if form validCommentedOct 25, 2013 at 16:03
1

What is your < form ... > node definition?

Did you define a target, a method (get/post)?

Note: sometimes, you could also need to disable request validation if you send strange data (like code, SQL etc.) in your form. To do that, put validateRequest="false" on your page definition in your ASPX file:

<@ Page [...]validateRequest="false"[...] %>

Note 2: don't forget to remove validateRequest="false" if it's not the answer - it could give you security issues.

2
  • thank you for answering me yes I just put a little bit of my code because satckoverflow don't allow to post a lot of code all run good when I remove this part of code submitHandler: function (form) { /* envoyer Mail*/ mailJob(); }CommentedOct 25, 2013 at 15:58
  • this is a function to be run after validate form just before calling the server sideCommentedOct 25, 2013 at 15:59
1

Disable your client validation first and make sure that when your form is submitted, it invoke the action with the HttpPost attribute on you controller.

[HttpPost] public ActionResult YourAction() 

Once this is working, re-enable your client validation and add

@Html.ValidationSummary(false) 

It will also help if you can use Chrome Dev Tools: Networking and the Console to check your traffic.

Edit: Add form.submit(); at the end of your mailJob() function. Your initial form submit was consumed by the submitHandler and no longer applies to your form.

7
  • thank you rachid as I say at first I am a beginnner, I have located the probleme is in submitHandler: function (form) { /* envoyer Mail*/ mailJob(); } I wanna to excute this function when my form is validCommentedOct 25, 2013 at 15:56
  • the probleme come with this methode submitHandler: function (form) { /* envoyer Mail*/ mailJob(); } it works fine when I remove thatCommentedOct 25, 2013 at 15:56
  • Please comment out the mailJob(); /*mailJob();*/ If your code works then it means you have something wrong in your mailJob() function. It would be helpful if you can list the code for that one as well.
    – Rachid
    CommentedOct 25, 2013 at 16:09
  • Do you have a mailJob() function defined somewhere in your code?
    – Rachid
    CommentedOct 25, 2013 at 16:13
  • yes and it works fine but it prevents the action methode to be excutedCommentedOct 25, 2013 at 16:17

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.