我使用ASP.NET MVC 5.剃刀上的文本字段属性VS密码字段
文本字段(注意htmlAttributes):
@Html.EditorFor(model => model.EmailAddr,
new { htmlAttributes = new { @class = "form-control" } })
密码字段(通知缺乏htmlAttributes的) :
@Html.PasswordFor(model => model.Passwd, new {@class = "form-control"})
这是我能使它工作的唯一方法。
在文本字段上,如果我拿走htmlAttributes
它不起作用。
在密码字段上,如果我添加htmlAttributes
,它不起作用。
为什么?
你不能在'htmlAttributes'传递给'EditorFor()'之前的MVC 5.1,但你可以写一个自定义模板或使用'TextBoxFor'代替。 –
HTML助手是静态方法的静态类,并且像对静态方法的任何调用一样,您需要给它一个正确的参数;我想如果你不需要它们,你可以添加'null'而不是'new htmlAttributes'。如果你确实需要PasswordFor的html属性,请concider编写自定义HTML助手。 –