Advertisement
Beginner ASP.NET Core, Controllers vs Minimal APIs

What is ControllerBase, and why do API controllers typically inherit from it rather than the full Controller class?

Short answer

ControllerBase provides the core functionality API controllers need -- action results (Ok, NotFound, BadRequest), model binding, and the request/response context -- without the additional view-rendering support (View(), ViewBag, ViewData) that the full Controller class adds…

Save ASP.NET Core mock interview
Advertisement
AModel answer
ControllerBase provides the core functionality API controllers need -- action results (Ok, NotFound, BadRequest), model binding, and the request/response context -- without the additional view-rendering support (View(), ViewBag, ViewData) that the full Controller class adds specifically for MVC applications returning HTML views, making ControllerBase the leaner, more appropriate base class for pure JSON/API-focused controllers.
// API controller: no view rendering needed
public class ProductsController : ControllerBase {
    [HttpGet]
    public IActionResult Get() => Ok(_products);
}

// MVC controller: needs view rendering support
public class HomeController : Controller {
    public IActionResult Index() => View();  // View() only available on Controller, not ControllerBase
}
Real-world example
A team building a pure JSON API consistently inherits from ControllerBase across every controller, since none of them ever need to render an HTML view, keeping the controllers' available surface area appropriately minimal.
Likely follow-ups
  • What specific members does Controller add on top of ControllerBase?
  • Can a single application mix controllers inheriting from each base class?
Related topics