如何将其他属性添加到htmlAttributes?

时间:2018-08-07 19:50:12

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

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

@ Html.EditorFor(model =>模型,新的{htmlAttributes =新的{@class =“表单 控制“}});

2 个答案:

答案 0 :(得分:1)

您将根据其外观将下一个属性放在htmlAttributes对象之外。相反,您需要这样做:

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

答案 1 :(得分:1)

您需要执行以下操作:

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