Reputation: 1388
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?
Upvotes: 4
Views: 4653
Reputation: 1
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.
Upvotes: 0
Reputation: 56
this may help
<%=Html.ValidationMessageFor(m => ((RegistrationFormModel)m.Data).Email, null, new { id = "registration_Email" })%>
Upvotes: 1
Reputation: 532465
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.
Upvotes: 0