ASP.NET Core MVC Interview Question #4
What is a controller in ASP.NET Core MVC?
MVC Fundamentals, Controllers, Views & Routing Junior Beginner
Quick Interview Answer
A controller is a class that groups related request-handling actions. MVC controllers normally inherit from Controller, which provides helpers such as View, RedirectToAction, NotFound, BadRequest, and access to ViewData, ViewBag, TempData, HttpContext, and ModelState.
Detailed Explanation
A controller is a class that groups related request-handling actions. MVC controllers normally inherit from Controller, which provides helpers such as View, RedirectToAction, NotFound, BadRequest, and access to ViewData, ViewBag, TempData, HttpContext, and ModelState.
Controllers should primarily coordinate the request. Business logic should normally be delegated to application or domain services so controllers remain focused and testable.
Code Example
public class ProductsController : Controller
{
public IActionResult Index()
{
return View();
}
}