1

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

Community
  • 1
  • 1
Arnab
  • 2,324
  • 6
  • 36
  • 60
  • Can you post some sample code what you have tried and also the message of the exception? – nemesv Oct 30 '11 at 21:25
  • code is the same as of http://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 Oct 31 '11 at 01:09
  • If my answer is not working for you please update your post with your actual code. – nemesv Oct 31 '11 at 09:01

1 Answers1

1

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")
                        )
                    );
            })
        )
    )
...
nemesv
  • 138,284
  • 16
  • 416
  • 359