1
votes

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

1
Can you post some sample code what you have tried and also the message of the exception? - nemesv
code is the same as of stackoverflow.com/questions/5732736/razor-nested-webgrid and the error seems to be coming because of the format option in mastergrid is somehow clashing with format in nested grid - Arnab
If my answer is not working for you please update your post with your actual code. - nemesv

1 Answers

1
votes

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