是否可以向 Razor 元素添加 class 和样式

Is it possible to add a class and a style to a Razor element

是否可以向 Razor 元素添加样式和 class 属性。

 <div style="width:170px;float:left;">
     @Html.DropDownListFor(m => m.SelectedPremise, Model.PremiseList, "Please select", new { @class = "selectpicker", data_style="btn-primary" ,style="width:100px;"})
  </div>

这行不通...

是的,可以添加。

查找以下示例以供参考。

  @Html.LabelFor(model => model.First, new Dictionary<string, object>() { { "class", "class-name" }, { "style", "display:none" } });