The routing mechanism provides enough to link to the routes in the application, however, at times, generating links pointing to specific routes becomes essential. We can achieve custom links using the link generation concept.
ASP.NET Core provides the UrlHelper class, an implementation of the IUrlHelper interface to build URLs for an ASP.NET Core application (MVC or web API). The methods CreatedAtRoute and CreatedAtAction are two inbuilt methods for link generation. Let's use them in an example:
using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; using System.Linq; namespace BasicRoute.Controllers { public class TodoController : Controller { // List containing Todo Items List<TodoTasks> TodoList = new List<TodoTasks>(); // Gets Todo item details based on Id ...