在格式化嵌套剃须刀的WebGrid [英] formatting in razor nested webgrid
问题描述
我筑巢另一个的WebGrid内的WebGrid如图剃刀嵌套的WebGrid
I'm nesting a webgrid inside another webgrid as shown in Razor Nested WebGrid
但是,当我尝试将列格式化嵌套的WebGrid它抛出一个错误,指出在mastergrid该列参数无效。在
But when I try to format the columns inside the nested webgrid it's throwing an error stating that the column in the mastergrid has invalid arguments.
有没有人遇到这个问题?
Has anyone faced this problem before?
有什么建议?
谢谢
ARNAB
Thanks Arnab
推荐答案
我猜你的问题是你的努力在内部使用相同的参数名称项目
格式
参数。你不能嵌套的lambda前pressions使用相同的参数名称。你可以找到这里更多关于拉姆达前pressions。
所以,你需要为内部格式中使用不同的参数名称(例如,子项目
)
I guess your problem is that you tried to use the same parameter name item
in the inner format
parameter. You cannot use the same parameter name in nested lambda expressions. You can find here more about lambda expressions.
So you need to use a different parameter name (e.g. subItem
) for the inner format:
...
@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", format: (subItem) => string.Format("Formatted: {0}", subItem.A)),
subGrid.Column("B")
)
);
})
)
)
...
这篇关于在格式化嵌套剃须刀的WebGrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!