ASP.NET Core Interview Question #110
What is an action method?
Routing, Controllers & Model Binding Mid-Level Intermediate
Quick Interview Answer
An action method is a public controller method that can be selected by routing to handle an HTTP request.
Detailed Explanation
An action method is a public controller method that can be selected by routing to handle an HTTP request.
Actions typically receive bound input values, call application services, and return IActionResult, ActionResult<T>, a specific result type, or another supported return value.
Methods that should not be considered actions can be marked with NonAction. Keeping actions small makes controllers easier to test and maintain.
Code Example
public class ProductsController : Controller
{
[HttpGet]
public IActionResult Details(int id)
{
return View();
}
[NonAction]
public string BuildTitle() => "Products";
}