Telerik UI Grid:绑定到模型的集合成员

时间:2014-07-17 13:56:30

标签: c# asp.net-mvc telerik

我有一个包含以下成员的模型:

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

我的视图中有一个表单(强烈输入Foo)以填充我的不同成员,但现在我想使用Telerik UI Grid让我的用户填写他们的bar。< / p>

很明显

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

不起作用。

我还尝试用List<Tuple<String, String>>替换List<Bar>并创建一个名为Bar的额外模型。然后我可以将我的网格绑定到此模型,但我不知道如何将其添加到Foo中的列表中,以便在提交表单时输入数据。

任何想法是否可行,如果可以,怎么做?似乎找不到这样做的例子。

1 个答案:

答案 0 :(得分:1)

嗯,您的电网需要&#34;工作&#34;列表,而不是包含列表的模型。

所以我宁愿选择类似

的东西
@(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%");
              })

那就是说,我不确定网格是否适用于Tuple<string, string> ......但值得一试;)

相关问题