首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用HtmlAttributes重载时TextAreaFor不工作

使用HtmlAttributes重载时TextAreaFor不工作
EN

Stack Overflow用户
提问于 2018-06-02 02:12:07
回答 2查看 351关注 0票数 0

由于某些原因,当我设置我的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" } })

我已经检查了文档,我确信我使用的是正确的重载。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-06-03 04:59:45

尝试如下所示:

@Html.TextAreaFor(m => m.AdminSetting.Style, 
    new { maxlength = 1000, @class = "form-control", @id = "HelloWorld" })

Html.TextAreaForHtml.EditorForHtml.DisplayFor这些帮助器的独特之处在于它们被称为“模板化帮助器”。他们能够实际使用视图来确定他们的输出结果,而不是仅仅输出一些定义好的HTML。这些视图分别被称为“编辑器模板”或“显示模板”。有关更多信息,请查看Html.EditorFor and htmlAttributes

希望这能帮到你。

票数 0
EN

Stack Overflow用户

发布于 2018-06-02 02:33:12

语法:

new { htmlAttributes = new { @class = "form-control", @style = "width: 100%;", @id = "HelloWorld" } })

表示ViewData的附加数据,可与EditorFor一起使用。

请参阅:MVC View htmlAttribute not working

MSDN - EditorFor

MSDN - TextAreaFor

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50648960

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档