【问题标题】:Add multiple css classes @Html.LabelFor添加多个 css 类 @Html.LabelFor
【发布时间】:2019-05-02 14:31:17
【问题描述】:

我想为 @Html.Label 添加多个 css 类,但它没有

我已经尝试了以下方法:

   @Html.LabelFor(model => model.ServiceName, htmlAttributes: new { @class = "SerivcesRegistrationLabel" , "control-label col-md-2" })


   @Html.LabelFor(model => model.ServiceName, htmlAttributes: new { @class = "SerivcesRegistrationLabel"  "control-label col-md-2" })

这两个都给我错误

【问题讨论】:

    标签: c# asp.net entity-framework model-view-controller asp.net-identity


    【解决方案1】:

    将所有类名放在一个字符串中,每个用空格分隔。喜欢:

    @class = "SerivcesRegistrationLabel control-label col-md-2"
    

    【讨论】:

      【解决方案2】:

      关闭。 Html 助手上的所有属性,如@id@class 都模拟了字符串实际显示为属性的方式,而实际上并未对其进行任何操作。因此,您可以像在实际元素上一样指定它,每个类后面都有一个空格。

       @Html.LabelFor(model => model.ServiceName, htmlAttributes: new { @class = "SerivcesRegistrationLabel control-label col-md-2" })
      

      每次在htmlAttributes 中使用逗号时,它都需要一个新属性,而不是另一个类。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-09-08
        • 2012-09-20
        • 2015-08-20
        • 1970-01-01
        • 1970-01-01
        • 2014-10-04
        • 1970-01-01
        • 2010-12-31
        相关资源
        最近更新 更多