Parminder
Parminder

Reputation: 3158

ModelState.AddModelError showing error twice

With MVC stuff when there is an error on property level, we can add error to ModelState but the same error is added to the summary also. How can we avoid to display it twice.

I want to display only public errors in the message summary and all other at property level.

Regards Parminder

Upvotes: 2

Views: 1618

Answers (1)

Kelsey
Kelsey

Reputation: 47726

When defining your validation summary set the first parameter to true which means Exclude Property Errors.

Eg:

<%= Html.ValidationSummary(true, "Unable to save item. Please correct the errors and try again.")%>

From MSDN:

excludePropertyErrors Type: System.Boolean

true to have the summary display model-level errors only, or false to have the summary display all errors.

Upvotes: 1

Related Questions