5

the source of LoginRegister view is like this :

@Html.Partial("authentication/_login")
@Html.Partial("authentication/_register")

and each child view has got a form with this syntax

@using (Html.BeginForm(**seperated-methods**, "Login")) 
{
    @Html.ValidationSummary(false)
} 

I send error(s) in postback whit this code

ModelState.AddModelError("", "**any-error-message**");
return View("authentication/LoginRegister", customized-data);

The point is , error message shows in both partial views.

gdoron
  • 147,333
  • 58
  • 291
  • 367
Mironline
  • 2,755
  • 7
  • 35
  • 61

1 Answers1

4

You need to tell the ModelState to which property this error refer to:

ModelState.AddModelError("PropertyName", "**any-error-message**");

Now it will be only in the

@Html.ValidationMessageFor(m => m.PropertyName)

If you don't specify the property name, the error will be considered global and get shown in every ValidationSummary.

gdoron
  • 147,333
  • 58
  • 291
  • 367