4

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

1 Answer 1

7

Change your html:

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

to

<div asp-validation-summary="All" class="text-danger"></div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.