如何在dot net core 3.0/3.1的剃须刀页面中添加区域? [英] How can Add Area in razor pages on dot net core 3.0/3.1?
问题描述
我想在 Razor Pages 中的核心3.1中添加区域,但是Microsoft文档适用于
您提供的图片中的 Index.cshtml
似乎不像我的Razor Pages结构.
Index.cshtml:
@page@model WebApplication1.Areas.Channel.Pages.IndexModel< h1>来自频道区域的问候//h1>
Index.cshtml.cs:
命名空间WebApplication1.Areas.Channel.Pages{公共类IndexModel:PageModel{公共无效的OnGet(){}}}
测试链接:
< a asp-area ="Channel" asp-page ="Index"> TestRedirect</a>
I want to add areas in core 3.1 in Razor Pages, but Microsoft documents are for asp dot net core 2.2, and they want to create a new report in January 2020!. Does somebody know how to add areas to the core 3.1?
I searched a lot on Google but couldn't find an answer.
in _AdminLayout :
...
<a asp-area="Channel" asp-page="Index" class="w3-bar-item w3-button w3-padding"><i class="fad fa-cog"></i> تنظیمات آپارات</a>
<a asp-page="Channel/Index" class="w3-bar-item w3-button w3-padding"><i class="fad fa-cog"></i> تنظیمات آپارات</a>
...
asp-area="Channel" asp-page="Index"
not work and even don't create url when clicked on current page refresh, but asp-page="Channel/Index"
work
and in Index (channel index)
@page "{area?}"
@model Aparat.Web.Areas.Channel.Pages.IndexModel
@{
Layout = "_AdminLayout";
}
<h1>INDDDEX</h1>
It works well when I add areas using below steps.
Create a brand new asp.net core 3.0/3.1 Web Application,in Channel
area, right click Pages
folder, select Add -> New Item -> Razor Page and create Index.cshtml
, you will get
Your Index.cshtml
does not seems to be Razor Pages structure like mine from your provided picture.
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()
{
}
}
}
Test link:
<a asp-area="Channel" asp-page="Index">TestRedirect</a>
这篇关于如何在dot net core 3.0/3.1的剃须刀页面中添加区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!