加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – DisplayFor忽略html属性的原因是什么?

发布时间:2020-12-16 06:31:49 所属栏目:asp.Net 来源:网络整理
导读:当试图使用它 @Html.DisplayFor(m = m.someField,new { htmlAttributes = "class = someclass" }) 该字段在渲染时不包含类someclass.我认为它是因为它只是写出文本而没有span元素或任何设置类的东西. 我真的想设置id,以便稍后我可以通过js更新它. 解决方法 c
当试图使用它

@Html.DisplayFor(m => m.someField,new { htmlAttributes = "class = someclass" })

该字段在渲染时不包含类someclass.我认为它是因为它只是写出文本而没有span元素或任何设置类的东西.

我真的想设置id,以便稍后我可以通过js更新它.

解决方法

class需要是@class

此评论有效

DisplayFor(),does not have any HTML attributes,thus u can’t do it.
Instead there are other ways of rendering the data inside a DIV/SPAN
with ur class.. – Nick Oct 16 at 11:15

此评论也有效

I think it should be @Html.DisplayFor(m => m.someField,new {@class=”someClass”}) – Michel Oct 16 at 11:30

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读