I ran into the following problem: https://github.com/aspnet/Mvc/issues/4989 , and based on the 'rsheptolut' comment of September 12, 2016, he found this workaround (inserted for convenience):
<form class="form-horizontal" asp-antiforgery="true">
<fieldset>
@if (!@ViewData.ModelState.IsValid)
{
var errors = ViewData.ModelState.Values.Select(item => item.Errors.FirstOrDefault()?.ErrorMessage).Where(item => item != null);
<div class="alert alert-danger">
<span>@Localizer["There are problems with your input:"]</span>
<ul>
@foreach (var error in errors)
{
<li>@error</li>
}
</ul>
</div>
}
</fieldset>
</form>
My problem is with LINQ to get the variable errors. I want to filter them by property name, so the list of errors listed in the file upload element will not contain errors of other elements on the page. I want to do something like this:
ViewData.ModelState.Values.Where(item => item.Key == "Images").Select...;
However, LINQ does not find Key as a valid property of the ModelStateEntry class. Fair. But why then, adding a quick scan to ViewData.ModelState.Values, does the Key property appear?