【发布时间】:2015-01-12 12:10:49
【问题描述】:
我的代码是这样的
@Html.EditorFor(model => model.CreatedUser, new { htmlAttributes = new { @class = "form-control" ,@placeholder = "Your Placeholder Text" }})
我希望占位符在我在代码中添加时出现,但它没有显示。谁能指出我做错了什么? 输出 HTML
<input class="text-box single-line" id="CreatedUser" name="CreatedUser" type="text" value="" autocomplete="off" style="cursor: auto; background-attachment: scroll; background-position: 100% 50%; background-repeat: no-repeat;">
【问题讨论】:
-
class有效吗?发布输出的 HTML -
这不适用于
EditorFor -
@mattytommo Nop。上课也不行。添加了输出 HTML
-
将
htmlAttributes分配给EditorFor()仅适用于MVC-5.1 -
只有当您为类型创建自定义
EditorTemplate时,您才能将属性作为ViewDataDictionary传递。我建议你使用TextBoxFor()
标签: c# asp.net-mvc razor asp.net-mvc-5