3

As above, I'm implemented the client side validation no problem, and it pops up the relevant messages as required. However, the submit button still appears to submit the form even though the form is not in a valid state.

The controller method throws it out immediately, because ModelState is not valid, but is there a flag/property I can check client side to prevent the post from happening at all?

UPDATE: The problem appears to be because the form is submitted asynchronously using a jquery post, hence my javascript method is posting the data regardless of the validation state. So what I'm looking for is, before I do that post, to do something along the lines of if( [Property/Method which indicates MVC Model State] == false ) return false;, however, I'm struggling to find such a method or property.

I've considered implementing a check function which identifies whether the 'input-validation-error' class is applied to any of my form fields. With JQuery, it's pretty simple, but it doesn't sit to well with me. Does anyone have any opinions on doing this?

On the one hand, it seems a bit of a hack because I'm effectively iterating through the form after it's been validated to see if it's actually valid. On the other hand, I'm not sure how the MVC JS would identify the modelstate if there were multiple forms on the same page, whereas if I was to do it myself, I could identify 'for the post of this form, I'm interested in these fields'.

Gavin
  • 2,311
  • 3
  • 19
  • 20
  • Maybe a stupid question but did you ``? – Darin Dimitrov Nov 22 '10 at 16:47
  • Did EnableClientValidation, yes. The form is actually built by a usercontrol, and is inside a div which is displayed using jquery-ui as a modal form. I'm not sure which of these factors is causing the problem, but the validation works correctly (preventing submit) on a more simple view that I have. The validation is running though, because it's flagging up the fields that are not valid. – Gavin Nov 22 '10 at 19:31

0 Answers0