The route name is also used by the UrlHelper class. For instance:
var url = Url.Route("Hello", new { controller = "SomeController", action = "SomeAction", name = "charlie", id = 123 });
This will result in the creation of an appropriate URL.
This feature is much more useful when using attribute routing. For example, if there is an action on some controller:
[RoutePrefix("api/phonebook")] public class PhonebookController { [HttpGet("contact/{id}", Name = "GetContact")] public Contact GetContact(int id) { ... } }
In other code, you can use Url.Route("GetContact", new { id = 7 }) to create the URL /api/phonebook/contact/7 .
source share