Hi @Shervan360
For example, I create a Razor page application and add the Products folder under the Pages folder, then add the following page with the @page
directive.
In my application, the application url is https://localhost:7215.
Then, to access the Pages/Index.cshtml page, we can use https://localhost:7215 or https://localhost:7215/Index or https://localhost:7215/Index/
To access the Pages/Add.cshtml page, we can use https://localhost:7215/Add or https://localhost:7215/Add/
To access the Pages/Products/Index.cshtml page, we can use https://localhost:7215/Products or https://localhost:7215/Products/Index or we can add a forward slash at the end of the url like this: https://localhost:7215/Products/Index/.
To access the Pages/Products/Create.cshtml page, we can use https://localhost:7215/Products/Create or https://localhost:7215/Products/Create/
To access the Pages/Products/Add.cshtml page, we have to use https://localhost:7215/Products/Add/AAA/Add or https://localhost:7215/Products/Add/AAA/Add/
So, from the above sample, we can know that, if we add the forward slash at the end of route template, like this: @page "/Products/Create"
or @page "/Products/Create/"
, we can access products Create.cshtml by browsing to both https://localhost:7215/Products/Create or https://localhost:7215/Products/Create/.
If we add a forward slash in front of the route template, it will use the template to specify an alternative route for a page that has no relationship with the file name. You can compare the request url between the Pages/Product/Create.cshtml page and Pages/Product/Add.cshtml page in the above sample, for the Add.cshtml page, since we didn't add the forward slash in front of the route template, it will append the template value at the end of the request url.
The override route template should start with /
or ~/
. We will not using './'
in the route template.
For the './', we might use it in the hyperlink, for example, in the Pages/Index page, we can add the following hyperlink:
<a asp-page="./Products/Create" >Product</a>
The generate html elements as below: you can also delete the '.', it will get the same result:
<a href="/Products/Create">Product</a>
More detail information about Routing in Razor page, see Razor Pages Routing
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion