问题描述
由于某些原因,当我设置我的TextAreaFor样式属性(特别是width属性)时,它不起作用,我的意思是宽度没有改变,Id也没有改变:
For some reasons, when I set my TextAreaFor style properties specifically the width property, it is not working, what I mean is the width is not changing, and the Id is not changing as well:
@Html.TextAreaFor(model => model.AdminSetting.Style, new { htmlAttributes = new
{ @class = "form-control", @style = "width: 100%;", @id = "HelloWorld" } })
但是,如果我删除了 htmlAttributes 一词,并将其更改为该词,那么它将正常工作.我真的很奇怪为什么:
But if I remove the word htmlAttributes and change it to this then it working fine. I really wonder why:
@Html.TextAreaFor(model => model.AdminSetting.Style,
new { @class = "form-control", @style = "width: 100%;", @id = "HelloWorld" })
除非我删除htmlAttributes声明并像这样声明它,否则我的TextAreaFor htmlAttributes 不能正常工作吗?
Is there reason why my TextAreaFor htmlAttributes not working unless I remove my declaration of htmlAttributes and declare it like this?
new { @class = "form-control", @style = "width: 100%;", @id = "HelloWorld" })
代替这个吗?
new { htmlAttributes = new
{ @class = "form-control", @style = "width: 100%;", @id = "HelloWorld" } })
我已经检查了文档,并且确定使用了正确的重载.
I've check the documentation, and I am sure that I am using the correct overload.
推荐答案
尝试如下所示:
@Html.TextAreaFor(m => m.AdminSetting.Style,
new { maxlength = 1000, @class = "form-control", @id = "HelloWorld" })
帮助者 Html.TextAreaFor
, Html.EditorFor
, Html.DisplayFor
都是独一无二的,因为它们被称为模板化的助手".它们不仅可以吐出一些 HTML
的定义位,还可以实际使用视图来确定其输出内容.这些视图分别称为编辑器模板"或显示模板".有关更多信息,请查看 Html.EditorFor和htmlAttributes .
The helpers, Html.TextAreaFor
, Html.EditorFor
, Html.DisplayFor
are unique in that they're what's referred to as "templated helpers". Instead of just spitting out some defined bit of HTML
, they're capable of actually using views to determine what their output will be. These views are referred to as "editor templates" or "display templates", respectively. For more information please have a look at Html.EditorFor and htmlAttributes.
希望这对您有帮助...
Hope this helps...
这篇关于使用HtmlAttributes重载时TextAreaFor无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!