caj*_*caj 37 asp.net html5 placeholder razor asp.net-mvc-5
我想在Html.EditorFor中使用占位符属性,所以我在第一个答案中就像:Html5占位符与.NET MVC 3 Razor EditorFor扩展?
但在最后一部分,我没有EditorTemplates文件夹,所以我创建它,当我尝试创建string.cshtml视图时我不能,因为名称"string"被保留所以我选择了stringg.cshtml而不是没用!我是否必须在程序的其他位置更改名称?我确实喜欢这个答案......
谢谢!
Med*_*edo 54
升级到MVC 5.1,您可以在EditorFor中使用HTML属性:
@Html.EditorFor(m => m.variable, new { htmlAttributes = new { placeholder = "Your Placeholder Text" } })
Run Code Online (Sandbox Code Playgroud)
http://www.asp.net/mvc/overview/releases/mvc51-release-notes
Jay*_*Jay 13
@Html.EditorFor(model => model.members_ssn, new { htmlAttributes = new { @class = "form-control", placeholder = "Your Example Here" } })
Run Code Online (Sandbox Code Playgroud)
这适用于 MVC 5。
就我而言,我希望从模型元数据中设置占位符,如下所示:
@Html.EditorFor(model => model.name, new { htmlAttributes = new { @class = "form-control", placeholder = Html.DisplayNameFor(x => x.name) } })
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
48751 次 |
| 最近记录: |