ASP.NET Core MVC Interview Question #83

What is URL generation in ASP.NET Core MVC?

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

Quick Interview Answer

URL generation creates a URL from route values instead of hard-coding a path. MVC helpers such as Url.Action, RedirectToAction, anchor Tag Helpers, and LinkGenerator use the configured endpoints to generate URLs.

Detailed Explanation

URL generation creates a URL from route values instead of hard-coding a path. MVC helpers such as Url.Action, RedirectToAction, anchor Tag Helpers, and LinkGenerator use the configured endpoints to generate URLs.

Route-aware URL generation improves maintainability because changes to route templates can often be handled centrally rather than requiring hard-coded links to be edited throughout the application.

Code Example

<a asp-controller="Products"
   asp-action="Details"
   asp-route-id="@Model.Id">
    Details
</a>