我已经尽我所能搜索了,但无济于事,希望这是一个简单的问题!
我将 Html.EditorFor 用于 ViewModel 对象中的集合。
但我希望表格的交替行具有交替类(“奇数”、“偶数”)。我尝试使用我在 SO 上采用的以下方法,但在编辑器模板中使用它会重置“计数”值,并且它使一切都相同。
@helper AlternativeBackgrounds(string style1, string style2)
{
if (ViewBag.count == null)
{
ViewBag.count = 0;
}
<text>class=" @(ViewBag.count % 2 == 1 ? style1 : style2)" </text>
ViewBag.count++;
}
如:
<tbody>
<tr @AlternativeBackgrounds("odd", "even")>
<td style="width:200px;">
这可以通过代码实现吗?
我想要达到的目标:
<tbody>
@Html.EditorFor(x => x.SomeCollection)
</tbody>
编辑器模板
@model = SomeModel
<tr class=??>
<td style="width:200px;">
@Html.LabelFor(x => x.SomeProperty)
</td>
<td>
@Html.LabelFor(x => x.SomeProperty)
</td>
... etc
</tr>
谢谢大家。