使用 HtmlAttributes 重载时 TextAreaFor 不工作
TextAreaFor Not Working When Using HtmlAttributes Overload
出于某些原因,当我专门设置我的 TextAreaFor 样式属性宽度 属性 时,它不起作用,我的意思是宽度没有改变,Id 也没有改变:
@Html.TextAreaFor(model => model.AdminSetting.Style, new { htmlAttributes = new
{ @class = "form-control", @style = "width: 100%;", @id = "HelloWorld" } })
但是如果我删除单词 htmlAttributes 并将其更改为这个,那么它工作正常。我真的很想知道为什么:
@Html.TextAreaFor(model => model.AdminSetting.Style,
new { @class = "form-control", @style = "width: 100%;", @id = "HelloWorld" })
有什么原因导致我的 TextAreaFor htmlAttributes 无法正常工作,除非我删除我的 htmlAttributes 声明并像这样声明它?
new { @class = "form-control", @style = "width: 100%;", @id = "HelloWorld" })
而不是这个?
new { htmlAttributes = new
{ @class = "form-control", @style = "width: 100%;", @id = "HelloWorld" } })
我已经检查了文档,我确定我使用了正确的重载。
语法:
new { htmlAttributes = new { @class = "form-control", @style = "width: 100%;", @id = "HelloWorld" } })
表示ViewData的附加数据,可与EditorFor
一起使用。
见:
尝试如下图:
@Html.TextAreaFor(m => m.AdminSetting.Style,
new { maxlength = 1000, @class = "form-control", @id = "HelloWorld" })
助手 Html.TextAreaFor
、Html.EditorFor
、Html.DisplayFor
的独特之处在于它们被称为 "templated helpers"。他们不只是吐出 HTML
的一些定义位,而是能够实际使用视图来确定他们的输出是什么。这些视图分别称为 "editor templates" 或 "display templates"。有关详细信息,请查看 Html.EditorFor and htmlAttributes.
希望这对您有所帮助...
出于某些原因,当我专门设置我的 TextAreaFor 样式属性宽度 属性 时,它不起作用,我的意思是宽度没有改变,Id 也没有改变:
@Html.TextAreaFor(model => model.AdminSetting.Style, new { htmlAttributes = new
{ @class = "form-control", @style = "width: 100%;", @id = "HelloWorld" } })
但是如果我删除单词 htmlAttributes 并将其更改为这个,那么它工作正常。我真的很想知道为什么:
@Html.TextAreaFor(model => model.AdminSetting.Style,
new { @class = "form-control", @style = "width: 100%;", @id = "HelloWorld" })
有什么原因导致我的 TextAreaFor htmlAttributes 无法正常工作,除非我删除我的 htmlAttributes 声明并像这样声明它?
new { @class = "form-control", @style = "width: 100%;", @id = "HelloWorld" })
而不是这个?
new { htmlAttributes = new
{ @class = "form-control", @style = "width: 100%;", @id = "HelloWorld" } })
我已经检查了文档,我确定我使用了正确的重载。
语法:
new { htmlAttributes = new { @class = "form-control", @style = "width: 100%;", @id = "HelloWorld" } })
表示ViewData的附加数据,可与EditorFor
一起使用。
见:
尝试如下图:
@Html.TextAreaFor(m => m.AdminSetting.Style,
new { maxlength = 1000, @class = "form-control", @id = "HelloWorld" })
助手 Html.TextAreaFor
、Html.EditorFor
、Html.DisplayFor
的独特之处在于它们被称为 "templated helpers"。他们不只是吐出 HTML
的一些定义位,而是能够实际使用视图来确定他们的输出是什么。这些视图分别称为 "editor templates" 或 "display templates"。有关详细信息,请查看 Html.EditorFor and htmlAttributes.
希望这对您有所帮助...