如何在 dot net core 3.0/3.1 的 razor 页面中添加区域?

How can Add Area in razor pages on dot net core 3.0/3.1?

我想在 Razor Pages 中添加核心 3.1 中的区域,但 Microsoft 文档是 asp dot net core 2.2, and they want to create a new report in January 2020!。有人知道如何向核心 3.1 添加区域吗?

我在 Google 上搜索了很多,但找不到答案。

在 _AdminLayout 中:

...
        <a asp-area="Channel" asp-page="Index" class="w3-bar-item w3-button w3-padding"><i class="fad fa-cog"></i>&nbsp; تنظیمات آپارات</a>
        <a asp-page="Channel/Index" class="w3-bar-item w3-button w3-padding"><i class="fad fa-cog"></i>&nbsp; تنظیمات آپارات</a>
...

asp-area="Channel" asp-page="Index" 无效,甚至在单击当前页面刷新时不创建 url,但 asp-page="Channel/Index" 有效

并在Index(频道索引)

@page "{area?}"
@model Aparat.Web.Areas.Channel.Pages.IndexModel
@{
    Layout = "_AdminLayout";
}

<h1>INDDDEX</h1>

当我使用以下步骤添加区域时效果很好。

创建一个全新的 asp.net core 3.0/3.1 Web Application,在Channel区域,右击Pages文件夹,select 添加 -> 新项目 -> Razor 页面并创建 Index.cshtml,你将得到

从你提供的图片看,你的 Index.cshtml 似乎不是我的 Razor Pages 结构。

Index.cshtml:

@page
@model WebApplication1.Areas.Channel.Pages.IndexModel

<h1>Hello from Channel Area</h1>

Index.cshtml.cs:

namespace WebApplication1.Areas.Channel.Pages
{
    public class IndexModel : PageModel
    {
        public void OnGet()
        {
        }
    }
}

测试link:

<a asp-area="Channel" asp-page="Index">TestRedirect</a>