ModelState.AddModelError shows error twice
With MVC stuff, when there is an error at the property level, we can add the error to ModelState
but the same error is added to the summary as well. How can we avoid showing it twice.
I want to display only public errors in the message summary and everything else at the property level.
Parminder relationship
+2
source to share
1 answer
When defining a validation summary, set the first parameter to true, which means Exclude Property Errors
.
For example:
<%= Html.ValidationSummary(true, "Unable to save item. Please correct the errors and try again.")%>
From MSDN :
excludePropertyErrors Type: System.Boolean
true to have only summary errors at the model level, or false to display all errors in the summary.
+1
source to share