DisplayFor忽略html属性的原因是什么? [英] What is the reason DisplayFor ignores html attributes?
问题描述
尝试使用此
@Html.DisplayFor(m => m.someField, new { htmlAttributes = "class = someclass" })
该字段在呈现时不包含someclass类.我之所以这样认为,是因为它只是写出文本,并且没有span元素或用于设置类的任何内容.
the field, when rendered does not contain class someclass. I supposed its because its just writing out the text and there isn't a span element or anything to set the class on.
我真的很想设置id,以便以后可以通过js更新它.
I'm really looking to set the id so that I can update it via js later on.
推荐答案
类必须为@class
此评论有效
DisplayFor(),没有任何HTML属性,因此您不能这样做. 相反,还有其他方法可以在DIV/SPAN中呈现数据 与您上课..–尼克10月16日,11:15
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
此评论也有效
我认为应该是@ Html.DisplayFor(m => m.someField,新 {@ class ="someClass"})–米歇尔10月16日在11:30
I think it should be @Html.DisplayFor(m => m.someField, new {@class="someClass"}) – Michel Oct 16 at 11:30
这篇关于DisplayFor忽略html属性的原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!