【问题标题】:How do I add other attributes to htmlAttributes?如何向 htmlAttributes 添加其他属性?
【发布时间】:2018-08-07 19:50:12
【问题描述】:

下面的代码有效,但是当我尝试将另一个属性添加到htmlAttributes 时,它会显示我无法执行此操作的错误。

@Html.EditorFor(model => model, new { htmlAttributes = new { @class= "form 控制" } });

【问题讨论】:

    标签: html asp.net asp.net-mvc


    【解决方案1】:

    从外观上看,您将下一个属性放在 htmlAttributes 对象之外。相反,你想要这个:

    @Html.EditorFor(model => model, new { htmlAttributes = new { @class = "form control", style = "background: blue" }})
    

    【讨论】:

      【解决方案2】:

      您需要执行以下操作:

      @Html.EditorFor(model => model, htmlAttributes: new { @class = "form control",
                                                            id="id" 
                                                          } 
                     })
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-11-25
        • 1970-01-01
        • 2021-09-24
        • 1970-01-01
        • 1970-01-01
        • 2011-11-20
        • 1970-01-01
        相关资源
        最近更新 更多