ASP.NET Core MVC Interview Question #26

What are action selectors in ASP.NET Core MVC?

Controllers, Actions, Model Binding & Action Results Junior Beginner

Quick Interview Answer

Action selectors help MVC determine which action method can handle a request. HTTP method attributes such as HttpGet, HttpPost, HttpPut, and HttpDelete constrain an action to particular request methods, while routing attributes can further constrain the URL.

Detailed Explanation

Action selectors help MVC determine which action method can handle a request. HTTP method attributes such as HttpGet, HttpPost, HttpPut, and HttpDelete constrain an action to particular request methods, while routing attributes can further constrain the URL.

Clear action selection prevents ambiguous routes and makes the intended HTTP behavior explicit.

Code Example

[HttpGet]
public IActionResult Edit(int id) => View();

[HttpPost]
public IActionResult Edit(ProductEditViewModel model)
{
    return View(model);
}