ModelState is ASP.NET Core’s record of model-binding and validation results for an HTTP request. It becomes valid when no errors occur and invalid when binding or validation reports errors. section 6.2.1 section 6.4
Follow the request lifecycle from model binding through validation, automatic error handling, and action execution. section 6.2.1
With [ApiController], ModelState normally works automatically:
- Model binding converts request values into action parameters and complex types; binding failures produce an HTTP 400 response. section 6.2.1
- Validation checks built-in or custom validation attributes and IValidatableObject, recording the results in ModelState. section 6.2.1 section 6.4
- An invalid ModelState prevents the action method from running and returns HTTP 400 automatically. section 6.2.1
Customizing ModelState handling
Configure ApiBehaviorOptions with SuppressModelStateInvalidFilter = true when an endpoint must inspect invalid input itself. The action can then test ModelState.IsValid, create ValidationProblemDetails(ModelState), and return a status code such as HTTP 501 for an invalid pageSize. A ManualValidationFilterAttribute can apply the same opt-out selectively to a controller action while preserving [ApiController]. section 6.2.3 section 6.2.3 section 6.3.4


