首页 > 解决方案 > 无法将样式和占位符添加到 @Html.TextAreaFor

问题描述

我正在使用以下 html 标记:

@Html.TextAreaFor(Model => Model.TaxID, 
 new {styles = "width:30%; border-color: black; maxlength: 9" @placeholder = "xxxxxxxxx"})

我无法检索任何样式,最大长度超过 9 个字符,@placeholder 抛出错误。有人可以帮我弄这个吗。

标签: c#asp.net-mvcrazorhtml-helper

解决方案


这样做的正确方法是这样的,注意它应该是“style”而不是“styles”,你也错过了and和 the,之间的一个应该也在之外:styleplaceholdermaxlengthstyle

new { placeholder = "xxx", maxlength=9, style = "width:30%; border-color: black;" }

推荐阅读