I render a Validation Summary in my MVC 5 App as below:
@Html.Partial("_ValidationSummary", @ViewData.ModelState)
and the Partial View code is as below:
@model ModelStateDictionary
<div class="@(Html.ViewData.ModelState.IsValid ? "validation-summary-valid" : "validation-summary-errors") panel panel-danger"
data-valmsg-summary="true">
<div class="panel-heading">
Please, correct the following errors:
</div>
<div class="panel-body">
<ul>
@foreach (var modelError in Model.SelectMany(keyValuePair => keyValuePair.Value.Errors))
{
<li>@modelError</li>
<li>@modelError.ErrorMessage</li>
}
</ul>
</div>
</div>
This is working quite nicely - in that the error messages display for fields that are in error.
However - The name of the Field on the model that is error is not added - so I have a field for mobile number and for home phone and for work phone. If i put abc into each field then in my validation summary I get 3 error messages saying "Phone Number is Invalid" but I would like to add the field to the error message so that I can add that to the error message to the User will know which of the fields is in error?
Is there an easy way to tweak my current code to achieve this?