Controllers

Broadly speaking, a controller is a class with a group of methods called actions. An action, also known as an action method, is a method that handles the request. As per the convention used by the ASP.NET Core MVC framework, a controller is a class that:

  • Is instantiable; that is, an instance of that class can be created
  • Resides in the project's root-level folder, named Controllers
  • Inherits from an abstract class, Microsoft.AspNetCore.Mvc.Controller

The framework is flexible and would also treat an instantiable class as a controller if any one or more of the following holds good:

  • The class is decorated with the [Controller] attribute
  • The class name is suffixed with Controller, such as HomeController
  • The class derives from a ...

Get .NET Core 2.0 By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.