formatting in razor nested webgrid

前端 未结 1 1664
情歌与酒
情歌与酒 2021-01-25 11:48

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

1条回答
  •  不思量自难忘°
    2021-01-25 12:23

    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")
                            )
                        );
                })
            )
        )
    ...
    

    0 讨论(0)
提交回复
热议问题