如何在Html.EditorFor中使用占位符属性? [英] How can I use placeholder attribute with Html.EditorFor?

查看:480
本文介绍了如何在Html.EditorFor中使用占位符属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Html.EditorFor中使用占位符属性,所以我在第一个答案中就像这样:使用.NET MVC 3 Razor Editor进行扩展的Html5占位符?

I want to use the placeholder attribute in the Html.EditorFor so I did just like in the first answer: Html5 Placeholders with .NET MVC 3 Razor EditorFor extension?

但在最后一部分,我不知道我有EditTemplates文件夹,所以我创建它,当我尝试创建string.cshtml视图时,我不能,因为名称字符串是保留的,所以我选择了stringg.cshtml而它不起作用!我是否必须在程序的其他位置更改名称?我确实喜欢这个答案...

But in the final part, I don't have the EditorTemplates folder so I created it and when I tried to create the string.cshtml view I couldn't because the name "string" is reserved so I chose stringg.cshtml instead and it didn't work! Do I have to change the name elsewhere in my program? I did exactly like the answer...

谢谢!

推荐答案

升级到MVC 5.1,你可以在EditorFor中使用HTML属性:

Upgrade to MVC 5.1 and you can use HTML attributes in EditorFor:

@Html.EditorFor(m => m.variable, new { htmlAttributes = new { placeholder = "Your Placeholder Text" } })

http://www.asp.net/mvc/overview/releases/mvc51-release-备注

这篇关于如何在Html.EditorFor中使用占位符属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆