c# - MVC Helper TextArea - 占位符不显示

标签 c# asp.net-mvc html-helper

我的 .cshtml 中有以下代码:

 @Html.TextArea("txtComments", new { style = "width: 450px;", placeholder = "Enter Comments here" })

但是占位符根本不显示。我错过了什么吗?

来源:

<textarea cols="20" id="txtComments" name="txtComments" placeholder="Enter Comments here" rows="2" style="width: 450px;">
</textarea>

最佳答案

在样式和占位符之前放一个@,就像这样,甚至可以在它之前放上 htmlAttributes:

@Html.TextArea("txtComments", htmlAttributes: new { @style = "width: 450px;", @placeholder = "Enter Comments here" })

这是我得到的准确输出:

<textarea cols="20" id="txtComments" name="txtComments" placeholder="Enter Comments here" rows="2" style="width: 450px;"></textarea>

如果显示占位符但仍未显示,请确保您使用的是最新的网络浏览器,您可以在此处找到支持的浏览器列表:http://caniuse.com/input-placeholder

< IE10 does not support it.

如果您确实需要这些浏览器的支持,也许这个解决方案会对您有所帮助:http://webdesignerwall.com/tutorials/cross-browser-html5-placeholder-text

关于c# - MVC Helper TextArea - 占位符不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15021268/

相关文章:

c# - 从包含通用 O​​bservableCollection 的类型 (System.type) 中获取字符串 "System.Collections.ObjectModel.ObservableCollection"?

c# - 如何处理 IDisposable?

javascript - 在 jQuery 中访问 Html 编码的字段值

asp.net-mvc - 如何在ASP.NET MVC中定义 View 级变量?

javascript - 如何设置通过查看 MVC URL 选择的下拉选项

c# - 从输入中减去输出音频流

c# - 为什么 NUnit 会忽略我的 C# 源代码中的测试?

jquery - 渲染部分 View 时 jquery 的 $(document).ready() 如何 react ?

asp.net-mvc - asp.net mvc : why is Html. CheckBox 生成额外的隐藏输入

c# - 在一次提交中创建多条记录