I\'m nesting a webgrid inside another webgrid as shown in Razor Nested WebGrid
But when I try to format the columns inside the nested webgrid it\'s throwing an error sta
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")
)
);
})
)
)
...