如何在 html table 单元格中使用 ASP.NET 标签助手
How to use ASP.NET Tag Helpers inside html table cells
在这个Microsoft Tutorial how can we display the html cell labels and values using ASP.NET HTML Tag Helpers?例如,在本教程的以下代码中,我想使用标签助手而不是使用 <td>@Html.DisplayFor(modelItem => item.BlogId)<\td>
。我尝试使用 <td><label asp-for="item.BlogId"></label><\td>
,但智能感知无法识别那里的 item in item.BlogId
。
label 中的 Tag Helpers 将显示 Display 属性名称 属性。要在视图中显示值 BlogId,您可以这样做。
<table>
@foreach (SampleApp.Controllers.Blog item in Model)
{
<tr><td>@item.BlogId</td></tr>
}
</table>
如果需要,可以将值包装在标签中。无需使用 asp-for 属性。
在这个Microsoft Tutorial how can we display the html cell labels and values using ASP.NET HTML Tag Helpers?例如,在本教程的以下代码中,我想使用标签助手而不是使用 <td>@Html.DisplayFor(modelItem => item.BlogId)<\td>
。我尝试使用 <td><label asp-for="item.BlogId"></label><\td>
,但智能感知无法识别那里的 item in item.BlogId
。
label 中的 Tag Helpers 将显示 Display 属性名称 属性。要在视图中显示值 BlogId,您可以这样做。
<table>
@foreach (SampleApp.Controllers.Blog item in Model)
{
<tr><td>@item.BlogId</td></tr>
}
</table>
如果需要,可以将值包装在标签中。无需使用 asp-for 属性。