The same problem is discussed in this post: Multiple forms in MVC view: ModelState applied to all forms.
I have followed along the post and also have several forms on the same view, custom editor template, have created and registered custom model binder. Here is the accompanying gist.
When I use the Html.ValidationResultFor()
helpers in the PasswordEditorViewModel.cshtml editor template I get the desired results:
<li class="error">@Html.ValidationMessageFor(i => i.OldPassword)</li>
<li class="error">@Html.ValidationMessageFor(i => i.NewPassword)</li>
<li class="error">@Html.ValidationMessage("PasswordChangeError.WrongPassword")</li>
This code returns validation errors exactly for the form I've posted.
On the other hand when I use the Html.ValidationSummary()
helper in the same editor template the validation result is propagated across all forms despite the fact I've posted only one:
Is this a normal behavior? Or have I missed something in the code?