首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何将其他属性添加到htmlAttributes?

如何将其他属性添加到htmlAttributes?
EN

Stack Overflow用户
提问于 2018-08-08 03:50:12
回答 2查看 157关注 0票数 -2

下面的代码可以工作,但是当我尝试向htmlAttributes添加另一个属性时,它显示一个错误,我不能这样做。

@Html.EditorFor(模型类模型,新{ htmlAttributes =新{@ => =“表单控件”} });

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-08-08 03:52:21

从外观上看,您要将下一个属性放在htmlAttributes对象的外部。相反,你想要的是:

代码语言:javascript
复制
@Html.EditorFor(model => model, new { htmlAttributes = new { @class = "form control", style = "background: blue" }})
票数 1
EN

Stack Overflow用户

发布于 2018-08-08 03:55:18

你需要做一些类似如下的事情:

代码语言:javascript
复制
@Html.EditorFor(model => model, htmlAttributes: new { @class = "form control",
                                                      id="id" 
                                                    } 
               })
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51734431

复制
相关文章

相似问题

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