I have a problem creating a table with dynamic columns. I add the columns in loop in this way:
for (int i = 0; i < attrIds.Count; i++)
{
resource_attr attr = resourceAttrRepository.Find(attrIds[i]);
int local = i;
columns.Add(new WebGridColumn()
{
ColumnName = attr.code,
Header = attr.resource_attr_name,
Style = "column-attr",
CanSort = true,
Format = (item) => (((List<string>)item.attrValues).Count < local) ? @item.attrValues[local] : "out"
});
}
The header column is correct, but the value is always showing "out."
I'm using ASP.Net MVC 4 and the WebGrid component.