Reputation: 4642
In Razor pages, I have the following folder structure:
The Index.cshtml page requires an Id of the person to be included as a Path parameter. I have defined the necessary @page directive in the cshtml file. The URL looks like this:
www.website.com/people/person/24
How can I use the @page directive to define the Jobs page to be the following route?
www.website.com/people/person/24/jobs
In other words, how can I do something like this, where pageName resolved to "Jobs"
@page "{personId}/{page}"
Using the reserved {page} routing template ends up returning an encoded route and not just the page name:
24/%2FPerson%2F/Jobs
Upvotes: 1
Views: 896
Reputation: 30110
You can apply a route template that overrides the default one generated by the routing system by prefixing it with a forward slash /
:
@page "/people/person/{personId:int}/jobs"
See here: https://www.learnrazorpages.com/razor-pages/routing#override-routes
As an aside, I would avoid using areas in Razor Pages applications altogether. You can get the same routing benefit by just adding subfolders to the Pages folder, without the extra complexity that areas add.
Upvotes: 2