Mid ASP.NET Core

Validation in API vs MVC (error response formatting)?

  • [ApiController] handles automatic validation:
  • Returns 400 BadRequest with ValidationProblemDetails if

ModelState.IsInvalid.

  • In MVC (without [ApiController]), you need to manually check

ModelState.IsValid.

if (!ModelState.IsValid) return View(model);

More from ASP.NET Core Tutorial

All questions for this course