views:

373

answers:

3

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?

A: 

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.

tvanfosson
I'm using Html.ValidationMessageFor
gugulethun
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.
gugulethun
Hmmm. Looks like it only generates a single set of validation metadata. You might need to use some alternate client-side validation.
tvanfosson
A: 

this may help

                <%=Html.ValidationMessageFor(m => ((RegistrationFormModel)m.Data).Email, null, new { id = "registration_Email" })%>
imlarry
that is you just specifies a custom id for the field insead of the generated one. Woks fine.
imlarry