keelerjr12
keelerjr12

Reputation: 1913

Nested/Sub-Areas in Razor Pages ASP.NET Core 2.2

I'm having trouble with getting nested (sub) Areas to work with Razor Pages. I would like to have a route structure like this:

/Index
/Admin
/Admin/Orders
/Admin/Inventory

My current file structure is the following:

/Pages
  /Index.cshtml
/Areas
  /Admin
    /Inventory
      /Pages
        /Index.cshtml
      /Models
    /Orders
      /Pages
        /Index.cshtml
      /Models
  /Product
    /Models
    /Pages

My Admin.Index page:

@page
@model ECommerceWeb.Areas.Admin.Pages.AdminModel
@{
    ViewData["Title"] = "Admin";
}

<h2>Admin</h2>

<ul>
    <li><a asp-page="Index" asp-area="Inventory">Inventory</a></li>
    <li><a asp-page="/Orders/Orders" asp-area="Admin">Orders</a></li>
</ul>

<form method="post">
    <button type="submit" name="action" value="logoutButton">Logout</button>
</form>

As you can see from the two <a> tags above, I've tried various approaches.

Upvotes: 2

Views: 1589

Answers (1)

keelerjr12
keelerjr12

Reputation: 1913

I solved this by re-structuring my application/folder structure to look like:

/Pages
  /Index.cshtml
/Areas
  /Admin
    /Models
      /Inventory
      /Orders
    /Pages
      /Inventory
        /Index.cshtml
      /Orders
        /Index.cshtml
  /Product
    /Models
    /Pages
      /Index.cshtml

Upvotes: 4

Related Questions