Before ASP.NET 2.1, you would need to explicitly look at the model validation result—for example, by inspecting ModelState.IsValid—and act accordingly, returning, for example, BadRequestResult. Since then, for any controllers that feature the [ApiController] attribute, ASP.NET Core will add an action filter called ModelStateInvalidFilter, which, before an action method is actually run, inspects the model for validity and returns BadRequestResult for us. The pseudocode looks as follows:
public void OnActionExecuting(ActionExecutingContext context)
{
if (!context.ModelState.IsValid)
{
context.Result = new BadRequestObjectResult(context.ModelState);
}
}
The response sent to the client includes the model validation errors and, by default, a special content type of application/problem+json. We will discuss this in greater detail when we talk about error handling later in this chapter.
You can disable this...