4

I have 4 forms in my asp.net mvc view. I have enabled client side validation on each by put <% Html.EnableClientValidation(); %> Above Html.BeginForm() of each form. The issue is that regardless of the fact that I've specified ID's for the forms the first form on the page gets validated whenever I click submit of the other forms.

Is this usage supported or am I doing something wrong?

3 Answers 3

1

this may help

                <%=Html.ValidationMessageFor(m => ((RegistrationFormModel)m.Data).Email, null, new { id = "registration_Email" })%>
Sign up to request clarification or add additional context in comments.

2 Comments

that is you just specifies a custom id for the field insead of the generated one. Woks fine.
Thanks, this got me out of a bind when using the same form in a partial for both adding new data and editing existing. just added a simple check to see if the primary key was 0 (ie, new data), and added a custom id for those.
0

Make sure you have validation messages for the properties. Unless you have a validation message or (ValidateFor()), the property isn't added to the set of elements validated on form submission.

See this question for more info.

3 Comments

I'm using Html.ValidationMessageFor
Client Side validation works with one form but as soon as I add more forms every time I click submit on the other forms the first form on the page will be validated.
Hmmm. Looks like it only generates a single set of validation metadata. You might need to use some alternate client-side validation.
0

MVC2 fully supports the setup that you're looking for, my guess is that you're applying this to something like displaying a registration form and a login form on the same page?

If so you just need each form to have independent property names, i.e.

LoginModel would have a Username property and RegistrationModel would have a RegistrationUsername.

Not a great example there, but what's probably happening is that the validation is firing cross form because your properties have the same name.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.