【问题标题】:Nested/Sub-Areas in Razor Pages w/ASP.NET Core 2.2带有 ASP.NET Core 2.2 的 Razor 页面中的嵌套/子区域
【发布时间】:2018-12-26 13:24:26
【问题描述】:

无法让嵌套(子)区域与 Razor 页面一起使用。我想要一个类似的路由结构:

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

目前我的文件结构如下:

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

我的Admin.Index 页面如下所示:

@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>

从上面的两个&lt;li>可以看出,我尝试了各种方法。

【问题讨论】:

    标签: c# asp.net-core asp.net-webpages


    【解决方案1】:

    我通过重新构建我的应用程序/文件夹结构来解决这个问题:

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

    【讨论】:

      猜你喜欢
      • 2019-11-22
      • 2018-03-11
      • 2016-12-18
      • 2021-09-28
      • 2019-11-12
      • 2020-05-06
      • 2019-03-12
      • 2019-12-27
      • 2019-11-02
      相关资源
      最近更新 更多