ActionResult<T>
noun
say it: “AK-shun rih-ZULT uv TEE” /ˈækʃən rɪˈzʌlt əv tiː/
An API action's return type that allows either the data itself or a status result such as NotFound().
What is ActionResult<T> in ASP.NET Core?
ActionResult<T> — A return type for an API action that can send back either the data itself, a T, or a status result such as NotFound() or BadRequest(). Unlike IActionResult, it tells tools like OpenAPI what type a success returns.
[HttpGet("{id}")]
public ActionResult<Product> GetById(int id)
{
Product? product = productDao.GetById(id);
if (product is null) return NotFound();
return product;
}
In a sentence
- “GetById returns ActionResult<Product>, so it can return the product or NotFound().”
Level: Journeyman · More ASP.NET Core terms at this level
Updated