【发布时间】:2025-12-30 07:35:06
【问题描述】:
从 MVC 5.1 开始,可以向编辑器模板添加 html 属性,如下所示:
@Html.EditorFor(m => m.Foo, new { htmlAttributes = new { id = "fooId", @class="fooClass" } })
如果属性Foo 的类型为string,它将正确生成输入标记,包括自定义属性。
但如果属性Foo 的类型为bool(或bool?),则属性将被忽略...
我在这里遗漏了什么吗?难道生成“选择”标记的模板仍然不支持此功能?
【问题讨论】:
-
你确定吗?对我来说一切正常。所有属性都包含在
bool属性中。 -
是的!如果我只是将属性类型更改为
string,则不会忽略属性。
标签: asp.net-mvc editorfor