如何在MVC中使用占位符作为编辑器? [英] How to use the placeholder in MVC for the editorfor?
问题描述
我想在@ Html.EditorFor中使用占位符来获取mvc中的文本。我试过很多东西甚至在谷歌搜索,但无论我得到的答案都不起作用。我很惊讶...... !!!最后我问了一下。
我最新的占位符代码是
I want to use placeholder in @Html.EditorFor for text in mvc. I tried many of things even search in google but whatever the answer I got that not work. I surprised...!!!. And finally I ask in question.
My lastest code for placeholder is
@Html.EditorFor(model => model.ToEmail, new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter Your EmailID...!!!" } })
此代码也不起作用。
谢谢。
我尝试过的事情:
我尝试了很多东西但没有工作。
This code also not work.
Thank You.
What I have tried:
I tried many things but not work.
推荐答案
您已将问题标记为MVC4。在MVC 5.1中添加了对EditorFor
中的自定义HTML属性的支持:
You've tagged your question as MVC4. Support for custom HTML attributes inEditorFor
was added in MVC 5.1:
我们现在允许在EditorFor中传入HTML属性作为匿名对象。
We now allow passing in HTML attributes in EditorFor as an anonymous object.
您需要将项目升级到MVC 5.1:
如何将ASP.NET MVC 4和Web API项目升级到ASP.NET MVC 5和Web API 2 | Microsoft Docs [ ^ ]
这篇关于如何在MVC中使用占位符作为编辑器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!