我目前有一个使用Razor Pages的.net核心Web应用程序(.Net core 3.1)。我具有以下文件夹结构。
Areas (folder)
Users (folder)
Pages (folder)
Index.cshtml
Edit.cshtml
在Index.cshtml里面,我有下面的查看代码。当应用程序运行时,它不会生成href,而当我检查html时,它将生成html,如下所示:
<a class="nav-link text-dark" asp-area="Users" asp-page="/Edit" asp-route-id="56591c1d-88af-48b6-b41b-1948af412511">Edit</a>
@page
@model MyApp.Areas.User.Pages.IndexModel
@{
ViewData["Title"] = "Users";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h1>Users</h1>
<table class="table">
<thead>
<tr>
<th>Operations</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.Users)
{
<tr>
<td>
<a class="nav-link text-dark" asp-area="Users" asp-page="/Edit" asp-route-id="@item.UserId">Edit</a> |
</td>
</tr>
}
</tbody>
</table>
答案 0 :(得分:1)
我丢失了 _ViewImports.cshtml
@using MyApp.Areas.Users
@using MyApp.Areas.Users.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers