本文介绍了剃刀嵌套的WebGrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何嵌套的WebGrid有很多关于每列的格式。我可以做一个嵌套的循环,但我需要它主要用于分页。或者有没有其他更好的选择?
How do I have nested WebGrid with lot of formatting for each column. I can do a nested for-loop, but I need it basically for paging. Or is there any other better option?
推荐答案
请问冗长的数据设置,但这个工程...
Excuse the verbose data setup but this works...
@{
var data = Enumerable.Range(0, 10).Select(i => new { Index = i, SubItems = new object[] { new { A = "A" + i, B = "B" + (i * i) } } }).ToArray();
WebGrid topGrid = new WebGrid(data);
}
@topGrid.GetHtml(columns:
topGrid.Columns(
topGrid.Column("Index"),
topGrid.Column("SubItems", format: (item) =>
{
WebGrid subGrid = subGrid = new WebGrid(item.SubItems);
return subGrid.GetHtml(
columns: subGrid.Columns(
subGrid.Column("A"),
subGrid.Column("B")
)
);
})
)
)
渲染:结果
Renders:
当然,你必须确保在GetHtml()方法调用你给每个网格(顶部和子)寻呼唯一参数名称/排序或你有冲突的结束。
Of course you'll have to make sure in the GetHtml() method calls you give each grid (both top and sub) unique parameter names for paging/sorting or you'll end up with conflicts.
这篇关于剃刀嵌套的WebGrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!