Home > Enterprise >  asp-page with multiple asp-routes not finding page
asp-page with multiple asp-routes not finding page

Time:01-20

I have a Razor page with the following @page and model:

@page "{slug1}/{slug2}/{someId:Guid?}/{step:int}"

--

public async Task<PageResult> OnGetAsync(string slug1, string slug2, Guid? someId, int step = 1)
{
    //...
}

On another page I link to the page in question like this (notice the missing "someId"):

<a asp-page="thepage" asp-route-Slug1="slug1" asp-route-Slug2="slug2" asp-route-Step="3">Open step 3</a>

But the link doesn't work (instead linking to its own page). If asp-route-SomeId is present in the link (with a valid GUID - not empty), the link works - with and without asp-route-Step.

Also, calling the link with only the two slugs works fine.

If I remove the /{step:int} from the @page it also works, but then the URL will end with ?Step=3 and I'd like to avoid that.

Is this some kind of limitation I don't see, or am I doing something wrong?

My goal is to be able to link to the page with and without someId in the URL and without ? in the URL.

CodePudding user response:

You can try to put {someId:Guid?} after {step:int}:

@page "{slug1}/{slug2}/{step:int}/{someId:Guid?}"
  •  Tags:  
  • Related