views:

106

answers:

1

I have a class that contains a property-value (property bag) dictionary beside normal properties. I'd like to display a collection of this object in a table using the grid from MvcContrib.

The class:

public class ObjectWithPropertyBag
{
   public string Property1 { get; set; }
   public string Property2 { get; set; }   

   public Dictionary<string, string> PropertyBag { get; set; }
}

My GridModel (ObjectWithPropertyBagGridModel):

Column.For(x => x.Property1);
Column.For(x => x.Property2);
Column.For(x => x.PropertyBag)//how to display keys as columns and values as table data

My view:

Html.Grid(ViewData.Model.ObjectWithPropertyBag).WithModel(new ObjectWithPropertyBagGridModel())

Is there any way to iterate through the dictionary and create the columns?

Thanks.

+1  A: 

Something like:

foreach (var prop in PropertyBag) column.For(prop.Value).Named(prop.Key);

I don't remember exact syntax, but as far as I remember you don't have to use lambdas. Or maybe it should be .For("").Value(prop.Value)... just check Grid's sources (or google) for overloads.

queen3