我像这样使用 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 语句。
最佳答案
你可以使用 Razor @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);
})
关于c# - 添加列时的 GridMvc 和 if 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24415461/