ASP.NET Core Interview Question #105

What are route parameters?

Routing, Controllers & Model Binding Mid-Level Intermediate

Quick Interview Answer

Route parameters are variable segments in a route template. Their values are extracted from the URL and made available to model binding.

Detailed Explanation

Route parameters are variable segments in a route template. Their values are extracted from the URL and made available to model binding.

For example, the template products/{id} matches /products/25 and produces an id route value of 25. Parameters can be optional, have defaults, or use constraints.

Meaningful route parameters help produce readable URLs and clearly identify the resource or action being requested.

Code Example

[HttpGet("products/{id:int}")]
public IActionResult Details(int id)
{
    return Ok(new { Id = id });
}