在MVC中将Kendo Grid与复杂模型绑定

时间:2016-12-02 14:10:09

标签: kendo-ui kendo-grid

我想在我的Kendo Grid中显示动态列,保持一列固定。 我的应用程序中有一个复杂的模型,下面是两个模型。

public class Product
{
    public string ProductId { get; set; }

    public int ProductQty { get; set; }

    public double ProductPrice { get; set; }
}

public class ProductLocation
{
    public string Location { get; set; }

    public List<Product> products { get; set; }
}

我将我的模型ProductLocation传递给View Kendo Grid所在的位置,我已经在我的控制器中填充了我的模型。

下面是我的Kendo Grid,我已将模型传递给它,并且我使用了foreach循环,以便我可以迭代显示我的动态列(Product),但我无法实现我的目标。我需要动态生成Product列,保持Location列固定。 Product列可能会根据位置而变化,因此我需要动态生成Kendo Grid中的列

@(Html.Kendo().Grid<MyNamespace.ProductLocation>()
        .Name("ProductDataGrid")
        .Columns(columns =>
        {
            columns.Bound(x => x.Location ).Width(25).HtmlAttributes(new { title = " #= Location # " }); //Tooltip

            //foreach (var prod in Model)
            //{
            //    columns.Group(group => group
            //    .Title(eqp.EqpType)
            //    .Columns(info =>
            //    {
            //        //info.Bound(prod.ProductId).Title("AVL").Width(15);
            //        //info.Bound(prod.ProductQty).Title("DMG").Width(15);
            //        //info.Bound(prod.ProductPrice).Title("RSV").Width(15);

            //    })
            //    .HeaderHtmlAttributes(new { style = "text-align:center" })
            //);
            //}
        })
        .Selectable()
        .AutoBind(false)
        .Pageable()
        .Scrollable(builder => builder.Enabled(true).Height("100%"))
        .DataSource(dataSource => dataSource.Ajax()
        .PageSize(10)
        .Read(read => read.Action("MyActionMethod", "MyController"))

    )

.Navigatable()
    .Pageable(p => p
                  .PageSizes(true)
                  .Refresh(true)
                  .ButtonCount(10)
                  )

请为此建议任何解决方案,以便我可以动态生成“产品”列。

感谢。

0 个答案:

没有答案