I have 4 forms in my asp.net mvc view. I have enabled client side validation on each by put <% Html.EnableClientValidation(); %>开发者_C百科
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?
this may help
<%=Html.ValidationMessageFor(m => ((RegistrationFormModel)m.Data).Email, null, new { id = "registration_Email" })%>
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.
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.
精彩评论