ASP.NET Core Razor Pages hierarchy with multiple route parameters

Viewed 1331

I'm trying to create an "item" page which is always inside an "inventory" using Razor Pages.

What I don't know is how to provide the id of the inventory to the item page

Let's say I have the following Pages structure

Pages Inventories Items

I assume I could have a route similar to /Inventories/{id}/Items/ and then /Inventories/{id}/Items/{itemid} to display a certain item but I'm not sure how. Or is there a better way to do it?

1 Answers

In asp.net core 2.1 Razor Pages, you could use Custom Routes to specify a custom route to a page.

@page "/Inventories/{id:int}/Items/{itemid:int}"

And you could get id by using

public async Task<IActionResult> OnGetAsync(int? id, int? itemid)
Related