ASP.NET Core MVC Interview Question #80

What are route tokens such as [controller] and [action]?

Advanced Routing, Filters, Areas & Application Structure Mid-Level Intermediate

Quick Interview Answer

Attribute routing supports replacement tokens such as [controller], [action], and [area]. At application startup, MVC replaces these tokens with values derived from the controller, action, or area.

Detailed Explanation

Attribute routing supports replacement tokens such as [controller], [action], and [area]. At application startup, MVC replaces these tokens with values derived from the controller, action, or area.

Tokens reduce repeated route text and can make route conventions easier to maintain, but public URLs should still be reviewed carefully before controller or action names are changed.

Code Example

[Route("[controller]/[action]")]
public class ProductsController : Controller
{
    [HttpGet("{id:int}")]
    public IActionResult Details(int id) => View();
}