Dynamic column with value appearing wrong in WebGrid

0

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.

    
asked by anonymous 17.11.2014 / 14:13

1 answer

1

The Value always appears OUT because it falls in the else if ternary

Format = (item) => (((List<string>)item.attrValues).Count < local) ? @item.attrValues[local] : "SEMPRE ESTÁ CAINDO AQUI."
    
17.11.2014 / 14:39