ASP.NET Core MVC Interview Question #7

What is the difference between Controller and ControllerBase?

MVC Fundamentals, Controllers, Views & Routing Junior Beginner

Quick Interview Answer

ControllerBase provides the core functionality needed for controller-based request handling, including HttpContext, routing data, ModelState, and response helper methods. It does not provide view-specific functionality.

Detailed Explanation

ControllerBase provides the core functionality needed for controller-based request handling, including HttpContext, routing data, ModelState, and response helper methods. It does not provide view-specific functionality.

Controller inherits from ControllerBase and adds support for MVC views, including View(), ViewData, ViewBag, and TempData. For server-rendered MVC pages, Controller is normally used; for controllers that only expose HTTP APIs, ControllerBase is commonly sufficient.

Code Example

public class HomeController : Controller
{
    public IActionResult Index() => View();
}

// API-style controller
[ApiController]
public class ProductsApiController : ControllerBase
{
}