[ApiController]
An attribute that switches on web API conventions for a controller, including automatic 400 responses for invalid models and inferred binding sources.
In more detail
It is placed on the controller class, or once on an assembly for every controller in it. With it, validation failures become a Problem Details response before the action body runs, with no if statement in every action.
Related terms
- controller — In ASP.NET Core, a class deriving from ControllerBase that groups related HTTP endpoints as methods called actions.
- model validation — Checking that incoming data meets the rules, such as required fields and ranges, before the application acts on it.
- Problem Details — A standard JSON shape for HTTP error responses, defined in RFC 9457, with members such as type, title, status, detail and instance.
Taught in
- Building Routes with Controllers — Modern .NET Core, C# & Enterprise Microservices