用于输入的MVC5占位符不起作用 [英] MVC5 placeholder for input not working
本文介绍了用于输入的MVC5占位符不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码就是这样
@Html.EditorFor(model => model.CreatedUser, new { htmlAttributes = new { @class = "form-control" ,@placeholder = "Your Placeholder Text" }})
我希望在代码中添加占位符,但不会显示.谁能指出我做错了什么? 输出HTML
I expect the placeholder to come up as I added in the code, but it's not showing. Can anyone point out what I am doing wrong? Output 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;">
推荐答案
接受htmlAttributes
的EditorFor
重载仅是MVC 5.1.
That EditorFor
overload that accepts the htmlAttributes
is MVC 5.1 only.
请参见此处
如果无法升级,请使用TextBoxFor
:
If upgrading is not an option, use TextBoxFor
:
@Html.TextBoxFor(model => model.CreatedUser, new { @class = "form-control" ,@placeholder = "Your Placeholder Text" })
这篇关于用于输入的MVC5占位符不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文