在使用@HTML命令时,我在向文本区域添加某些html属性时遇到问题。我只是想添加一个类名,但它不起作用。
下面是我的代码:
@Html.TextAreaFor(model => model.Message, new { htmlAttributes = new { @class = "required-field" } })它正在产生:
<textarea id="Message" rows="2" name="Message" htmlattributes="{ class = required-field }" data-val-required="The Message field is required." data-val="true" cols="20"></textarea>我不知道为什么它显示的是htmlattributes="{ class== required-field }“而不是”required-field“,因为相同的代码适用于普通文本输入-即@Html.EditorFor(model => model.Email, new { htmlAttributes = new { @class = "required-field" } })
工作正常。
任何帮助都将不胜感激
发布于 2015-12-07 06:14:38
感谢Stephen Muecke "Its @Html.TextAreaFor(模型类字段,新{@ => =“model.Message”})“
https://stackoverflow.com/questions/34123448
复制相似问题