ASP.NET Core Web API Interview Question #43

What is the difference between IActionResult and ActionResult<T>?

DTOs, Model Binding, Validation & API Responses Junior Beginner

Quick Interview Answer

IActionResult represents an HTTP action result without declaring a specific successful body type in the method signature. ActionResult<T> combines a known success type with the ability to return other HTTP results.

Detailed Explanation

IActionResult represents an HTTP action result without declaring a specific successful body type in the method signature. ActionResult<T> combines a known success type with the ability to return other HTTP results.

For data-returning API endpoints, ActionResult<T> often makes the contract clearer. IActionResult remains appropriate when an action can return several unrelated response shapes or no typed body is meaningful.

Code Example

public IActionResult Delete(int id)
    => NoContent();

public ActionResult<ProductResponse> Get(int id)
    => new ProductResponse { Id = id };