在 ASP.NET 核心 2.0 视图中设置标签助手的 Html 属性

Setting Html Attributes in Tag Helpers in ASP.NET Core 2.0 Views

我正在将我的 Web 应用程序从 ASP.NET MVC 迁移到 ASP.NET Core 2.0。但是我在 Select 标签的标签助手中设置 html 属性时遇到问题。例如,在我的旧项目中,我有下面的 html 下拉列表助手。

var cssClass = "select-arrow " + Model.ControlCss;                        
@Html.DropDownListFor(model => model.Value, options, "", new { @class = cssClass })

在这里,我使用 html 助手 class 的波纹管 html 属性来添加另一个 CSS classes.

new { @class = cssClass }

现在我的问题是如何在 asp.net 核心中设置 html 属性?打击代码有效吗?请告诉我详情。

<select asp-for="Value" asp-items="options" class="form-control, cssClass"></select>

您可以使用 @PropertyName:

插入字符串
<select asp-for="Value" asp-items="options" class="form-control select-arrow @Model.ControlCss" />