我正在使用 GridMvc,例如:
@Html.Grid(Model.Customers).Columns(columns =>
{
columns.Add(x => x.FirstName).Titled(Translations.Global.FIRST_NAME).SetWidth(110).Sortable(true);
...
我如何在这里使用 if 语句。我想创建 if 语句,例如:
if (x.LastName == 'Me')
{
<span class="label label-success">Active</span>
}
else
{
<span class="label label-important">Banned</span>
}
但我不知道如何在 gridmvc 中创建 if 语句。
你会使用剃须刀@helper 并做类似的事情吗
@helper CustomRenderingOfColumn(Customer customer)
{
if (customer.LastName == 'Me')
{
<span class="label label-success">Active</span>
}
else
{
<span class="label label-important">Banned</span>
}
}
那么在你的网格中会看起来像
@Html.Grid(Model).Columns(columns =>
{
columns.Add(o => o.Customer.IsVip)
.Titled("Vip customer")
columns.Add(x=>x.FirstName)
.Titled(Translations.Global.FIRST_NAME)
.SetWidth(110)
.RenderValueAs(o => CustomRenderingOfColumn(o))
.Sortable(true);
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)