Arnab
Arnab

Reputation: 2354

formatting in razor nested webgrid

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 stating that the column in the mastergrid has invalid arguments.

Has anyone faced this problem before?

Any suggestions?

Thanks Arnab

Upvotes: 1

Views: 3416

Answers (1)

nemesv
nemesv

Reputation: 139758

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

Upvotes: 1

Related Questions