Home > database >  How to specify a custom route name for razor page
How to specify a custom route name for razor page

Time:10-19

Is there a way to specify a custom route name for a razor page?

For controllers and actions, it's possible by, for example, using the RouteAttribute like this:

[Route("my-custom")]
public class MyCustomController
{
    [Route("my-index")]
    public IActionResult MyIndex() => View();
}

Is there any similar approach regarding razor pages?

CodePudding user response:

It's possible by customizing the routing template of the @page directive within the cshtml file.
In the MyIndexPage.cshtml razor page, for example;

@page '/my-index'
@model MyIndexPageModel

...

Without forgetting the forward slash (/) at the beginning.

  • Related