由于某些原因,当我设置我的TextAreaFor样式属性,特别是宽度属性时,它不起作用,我的意思是宽度没有改变,Id也没有改变:
@Html.TextAreaFor(model => model.AdminSetting.Style, new { htmlAttributes = new
{ @class = "form-control", @style = "width: 100%;", @id = "HelloWorld" } })
但是,如果我删除单词htmlAttributes并将其更改为this,则它可以正常工作。我真的想知道为什么:
@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" } })
我已经检查了文档,我确信我使用的是正确的重载。
发布于 2018-06-03 04:59:45
尝试如下所示:
@Html.TextAreaFor(m => m.AdminSetting.Style,
new { maxlength = 1000, @class = "form-control", @id = "HelloWorld" })
Html.TextAreaFor
、Html.EditorFor
、Html.DisplayFor
这些帮助器的独特之处在于它们被称为“模板化帮助器”。他们能够实际使用视图来确定他们的输出结果,而不是仅仅输出一些定义好的HTML
。这些视图分别被称为“编辑器模板”或“显示模板”。有关更多信息,请查看Html.EditorFor and htmlAttributes。
希望这能帮到你。
发布于 2018-06-02 02:33:12
语法:
new { htmlAttributes = new { @class = "form-control", @style = "width: 100%;", @id = "HelloWorld" } })
表示ViewData的附加数据,可与EditorFor
一起使用。
https://stackoverflow.com/questions/50648960
复制相似问题