Search code examples
asp.net-mvcasp.net-mvc-3razorwebgrid

MVC Webgrid Column Pointing to Array Indices - is this possible?


I'm playing with the MVC Webgrid in a project, pretty impressed so far, but I think I've found one restriction to it's capabilities, which I'm assuming is due to the nature of its reflection capabilities.

It seems quite alright to point at data as such:

var grid = new WebGrid(source: Model); //this has Model.Data - an IEnumerable list of "whatever".
grid.Columns(grid.Column("Data.SomeProperty"));

However you can't access a value in an array, such as:

grid.Columns(grid.Column("Data.SomeArray[0]"));

Which seems fair enough, as what I'm trying to do with this is a bit cheeky, but I just wondered if I'm missing something & this is technically possible...

Many thanks


Solution

  • Try like this:

    grid.Column("ColumnName", format: @<text>@item.Data.SomeArray[0]</text>)