ASP.NET Core MVC Interview Question #5
What is an action method in ASP.NET Core MVC?
MVC Fundamentals, Controllers, Views & Routing Junior Beginner
Quick Interview Answer
An action method is a public controller method that can be selected by MVC to handle a request. It accepts bound input values, performs or coordinates the required work, and returns a response such as a view, redirect, JSON result, file, status code, or another action result.
Detailed Explanation
An action method is a public controller method that can be selected by MVC to handle a request. It accepts bound input values, performs or coordinates the required work, and returns a response such as a view, redirect, JSON result, file, status code, or another action result.
Methods that should not be callable as actions can be marked with NonAction. Action selection can also be constrained with HTTP method attributes such as HttpGet and HttpPost.
Code Example
[HttpGet]
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(ProductInputModel model)
{
return View(model);
}