简体   繁体   English

MVC5占位符输入无法正常工作

[英]MVC5 placeholder for input not working

My code is like this 我的代码是这样的

 @Html.EditorFor(model => model.CreatedUser, new { htmlAttributes = new { @class = "form-control" ,@placeholder = "Your Placeholder Text"  }})

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 输出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;">

That EditorFor overload that accepts the htmlAttributes is MVC 5.1 only. 接受htmlAttributes EditorFor重载只是MVC 5.1。

See HERE 这里

If upgrading is not an option, use TextBoxFor : 如果不能选择升级,请使用TextBoxFor

@Html.TextBoxFor(model => model.CreatedUser, new { @class = "form-control" ,@placeholder = "Your Placeholder Text" })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM