Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp-validation-summary shows custom but not model errors

Asp-validation-summary in view shows errors added via ModelState.AddModelError, but don't show any model validation errors ("The User field is required."). I'm using Microsoft.AspNetCore.Mvc 1.0.0-rc2-final. Btw: User field is not displayed via the view but correctly identified by EF as a model level error before add.

//<div asp-validation-summary="ModelOnly" class="text-danger"></div> in view
ModelState.AddModelError(string.Empty, "This error shows up in validation-summary");
ViewBag.HeaderMessage = "Error: " + string.Join(" - ", ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage));

Errors show in field filled via ViewBag but not in validation-summary

like image 404
Ad Gerrits Avatar asked Mar 12 '23 01:03

Ad Gerrits


1 Answers

Change your html:

<div asp-validation-summary="ModelOnly" class="text-danger"></div>

to

<div asp-validation-summary="All" class="text-danger"></div>
like image 200
adem caglin Avatar answered Mar 23 '23 23:03

adem caglin