Asp.net mvc client side validation on multiple forms on one page

I have 4 forms in my asp.net mvc view. I have included client-side validation for everyone by placing <% Html.EnableClientValidation(); %> <% Html.EnableClientValidation(); %> Above Html.BeginForm() each form. The problem is that no matter what I specify the identifier for the forms, the first form on the page is checked whenever I click the submit button from other forms.

Is this use supported or am I doing something wrong?

+4
source share
3 answers

this can help

  <%=Html.ValidationMessageFor(m => ((RegistrationFormModel)m.Data).Email, null, new { id = "registration_Email" })%> 
+1
source

Make sure you have validation messages for properties. If you do not have a validation message or (ValidateFor ()), the property is not added to the set of elements validated when the form was submitted.

See question for details.

0
source

MVC2 fully supports the setup you are looking for, I assume that you are applying this to display the login form and login form on the same page?

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

LoginModel will have the Username property, and RegistrationModel will have the name RegistrationUsername.

Not a very good example, but it probably happens that validation is a cross-form because your properties have the same name.

0
source

Source: https://habr.com/ru/post/1304658/


All Articles