Kevin
Kevin

Reputation: 775

Telerik UI Grid: Bind to collection member of model

I have a model with the following member:

 public class Foo
 {
    public List< Tuple<String, String> > bar { get; set; }
    //more fields that do not matter in this case
 }

I have a form in my view (strongly typed to Foo) to fill my different members, but now I want to use the Telerik UI Grid to have my users fill in their bar.

It is clear that

   @(Html.Kendo().Grid<Foo>()
           .Name("Grid")
             .Columns(columns =>
             {
                 columns.Bound(e => e.bar);
                 columns.Command(command => { command.Edit(); command.Destroy();      }).Width("30%");
             })

does not work.

I also tried replacing List<Tuple<String, String>> with List<Bar> and create an extra model called Bar. I can then bind my grid to this model, but I have no idea how I can add it to the list in Foo, so that I have the data entered when submitting the form.

Any idea if this is possible and if yes, how to do this? Can't seem to find an example that does this.

Upvotes: 0

Views: 795

Answers (1)

Rapha&#235;l Althaus
Rapha&#235;l Althaus

Reputation: 60493

Well, your grid needs to "work" with a list, not a model containing a list.

So I would rather go for something like

@(Html.Kendo().Grid(Model.bar)//the grid is now working with the list
              .Name("Grid")
              .Columns(columns => {
                  columns.Bound(e => e.Item1);//first item in tuple
                  columns.Bound(e => e.Item2);//second item in tuple
                  columns.Command(command => {
                    command.Edit();
                    command.Destroy();
                  }).Width("30%");
              })

That said, I'm not sure that the grid will work with a Tuple<string, string>... but that's worth a try ;)

Upvotes: 1

Related Questions