【发布时间】:2022-10-16 06:03:17
【问题描述】:
我正在使用 .Net Core 6,目前我无法使其与标签助手一起使用元素。
<div class="container p-3">
<div class="row pt-4">
<div class="col-6">
<h2 class="text-primary">Category List</h2>
</div>
<div class="col-6 text-end">
<a asp-controller="Category" asp-action="Create" class="btn btn-primary">
<i class="bi bi-plus-circle"></i> Create new category
</a>
</div>
</div>
<br /><br />
<table class="table table-bordered table-striped" style="width: 100%;">
<thead>
<tr class="table-primary" ">
<th scope="row">Category Name</th>
<th scope="row">Display Order</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var category in Model)
{
<tr>
<td width="50%">@category.Name</td>
<td width="30%">@category.DisplayOrder</td>
<td>
<div class="w-75 btn-group" role="group">
<a asp-controller="Category" asp-action="Edit" asp-route-id="@category.Id" class="btn btn-primary mx-2">
<i class="bi bi-pencil-square"></i> Edit
</a>
</div>
</td>
</tr>
}
</tbody>
</table>
第一个锚在这里完美运行,
<a asp-controller="Category" asp-action="Create" class="btn btn-primary">
<i class="bi bi-plus-circle"></i> Create new category
</a>
但是,当我使用下一个并运行应用程序时,导航器无法识别该标记,也不会自动创建用于添加 href 标记的 sintax。
<a asp-controller="Category" asp-action="Edit" asp-route-id="@category.Id" class="btn btn-primary mx-2">
<i class="bi bi-pencil-square"></i> Edit
</a>
【问题讨论】:
-
顺便说一句,您的
<th scope="row">应该是<th scope="col">。 -
你的
CategoryController实际上有一个名为Edit的操作接受Int32 id路由参数? -
抱歉,是的,我有一个名为 Edit 的操作,它接收到一个参数 Int32 id。但是在那个位置,锚元素没有用 href 标签渲染。如果我手动将属性 href="Category/Edit/@category.Id" 添加到锚元素,它可以工作,但使用标签助手仍然不起作用。
标签: asp.net asp.net-core .net-core