添加CSS类剃须刀@ Html.DisplayFor [英] Adding a CSS class to razor @Html.DisplayFor
本文介绍了添加CSS类剃须刀@ Html.DisplayFor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要为我的code,这部分新的类,但它不能正常工作
I want to set a new class for this part of my code, but it doesn't work correctly
@Html.DisplayFor(model => model.melk.Code, new { @class = "myClass" } )
谁能告诉我在哪里,我错了?
Can anyone tell me where am I wrong?
推荐答案
的 DisplayExtensions.DisplayFor超载您正在使用会发现根据 model.melk。code类型的DisplayTemplate
最后一个参数(匿名对象新{@class =MyClass的}
将传递到模板的ViewData的,你必须使用的ViewData中,为了相应的模板它的工作。
The DisplayExtensions.DisplayFor overload that you are using will find the DisplayTemplate based on the type of the model.melk.Code
and the last parameter (anonymous object new { @class = "myClass" }
will be passed to the template's ViewData. You have to use that ViewData in the corresponding template in order for it to work.
<div class="@(ViewData["class"])"...
这篇关于添加CSS类剃须刀@ Html.DisplayFor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文