ApiController
ApiController is an ASP.NET Core attribute that enables API-specific conventions and behavior for controller classes, including request binding and validation handling.
ASP.NET Core in Action, 3e
ApiController is an ASP.NET Core attribute that enables conventions for web API controllers, including attribute routing, automatic validation responses, binding-source inference, and Problem Details responses.
- How it is used
- Reduces repetitive code and applies consistent conventions to ASP.NET Core web API controllers.
- How deep it goes
- Compares controllers with and without the attribute, explains its conventions, and demonstrates configuration and a validation-filter alternative.
- Examples
- Uses a fruit-list GET endpoint and an update action with a required name to illustrate controller behavior.
- What you can do after
- Apply it via ASP.NET Core to simplify controllers and configure automatic validation behavior.
Read how ASP.NET Core in Action, 3e explains ApiController →
Building Web APIs with ASP.NET Core
The ApiController attribute is an ASP.NET Core attribute that enables API-controller conventions, including automatic handling of model-binding and validation failures.
- How it is used
- Enables API-controller conventions and automatic responses to invalid request input.
- How deep it goes
- Traces binding and validation through ModelState, then shows how to suppress automatic HTTP 400 responses for manual handling.
- Examples
- Shows an invalid pageIndex response and Program.cs configuration for suppressing the automatic invalid-ModelState filter.
- What you can do after
- Operate/configure it to retain automatic validation or inspect ModelState manually when an action needs a custom response.
Read how Building Web APIs with ASP.NET Core explains ApiController →
Also covered in
What to know first
- 400 bad requestHTTP 400 Bad Request is a client-error status code indicating that a server cannot or will not process a request because of a client-side error.
- JSONJSON is a language-independent text-based data-interchange format that represents structured values using objects, arrays, strings, numbers, booleans, and null.
- model bindingModel binding is the process of locating incoming data, converting it to appropriate types, and assigning it to application objects or handler parameters.
- Model–view–controllerModel–view–controller is a software architectural pattern that separates application data and behavior, presentation, and interaction handling into model, view, and controller responsibilities.
Related concepts
- ModelState.IsValidcontrasts with · An ASP.NET Core property indicating whether model binding and validation completed without errors.
- automatic 400 responsesproduces · Automatic 400 responses are framework-generated Bad Request responses produced when API model validation fails.
- automatic model state validationconfigures · Automatic model state validation is the framework behavior that short-circuits an API action with a client-error response when ModelState is invalid.
- explicit routingconfigures · Explicit routing is a routing approach in which each endpoint is assigned a specific URL pattern directly, often through route templates or attributes.
- FromBody attributecontrasts with · The FromBody attribute directs ASP.NET Core model binding to deserialize a parameter or property value from the HTTP request body.
- model bindingconfigures · Model binding is the process of locating incoming data, converting it to appropriate types, and assigning it to application objects or handler parameters.
Questions about ApiController
What is ApiController?
ApiController is an ASP.NET Core attribute that enables API-specific conventions and behavior for controller classes, including request binding and validation handling.
Which Manning books explain ApiController?
ASP.NET Core in Action, 3e and Building Web APIs with ASP.NET Core.
What should I know before learning ApiController?
Manning books that teach ApiController usually introduce 400 bad request, JSON, model binding and Model–view–controller first.
What is the difference between ApiController and ModelState.IsValid?
ApiController is an ASP.NET Core attribute that enables API-specific conventions and behavior for controller classes, including request binding and validation handling. An ASP.NET Core property indicating whether model binding and validation completed without errors.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

