0

我正在尝试使用可扩展的行来获得这个基本的剑道 ui:

<div id="grid"></div>

<script type="text/javascript">
    $(function () {
        $("#grid").kendoGrid({
            columns: [
            {
                field: "ProductId",
                title: "ProductId"
            }
        ],
            dataSource: {
                type: "json",
                transport: {
                    read: '@Url.Action("GetData1", "MockForms")'
                }
            },
            height: 450,
            sortable: true,
            pageable: true,
            detailTemplate: "<h2 style='background-color: yellow;'>Expanded!</h2>",
            detailExpand: function (e) {
                this.collapseRow(this.tbody.find(' > tr.k-master-row').not(e.masterRow));
            }
        });
    });  
</script>

json是这样生成的:

public ActionResult GetData1([DataSourceRequest] DataSourceRequest request)
        {
            var list = new List<Product>
                {
                    new Product {ProductId = 1, ProductType = "SomeType 1", Name = "Name 1", Created = DateTime.UtcNow},
                    new Product {ProductId = 1, ProductType = "SomeType 2", Name = "Name 2", Created = DateTime.UtcNow},
                    new Product {ProductId = 1, ProductType = "SomeType 3", Name = "Name 3", Created = DateTime.UtcNow}
                };

            return Json(list.AsQueryable().ToDataSourceResult(request));
        }

并且似乎可以发送(根据萤火虫)。但是,没有任何约束(没有 javascript 错误)。有任何想法吗?

PS:

OnaBai 的第二条评论帮助我让它发挥作用。我变了:

return Json(list.AsQueryable().ToDataSourceResult(request));
=>
return Json(list);

产生这个 JSON:

[{"ProductId":1,"ProductType":"SomeType 1","Name":"Name 1","Created":"\/Date(1371022051570)\/"},{"ProductId":1,"ProductType":"SomeType 2","Name":"Name 2","Created":"\/Date(1371022051570)\/"},{"ProductId":1,"ProductType":"SomeType 3","Name":"Name 3","Created":"\/Date(1371022051570)\/"}]

我仍然想使用:

return Json(list.AsQueryable().ToDataSourceResult(request));

因为这最终会使分页和排序更容易。它目前生产:

{"Data":[{"ProductId":1,"ProductType":"SomeType 1","Name":"Name 1","Created":"\/Date(1371022186643)\/"},{"ProductId":1,"ProductType":"SomeType 2","Name":"Name 2","Created":"\/Date(1371022186648)\/"},{"ProductId":1,"ProductType":"SomeType 3","Name":"Name 3","Created":"\/Date(1371022186648)\/"}],"Total":3,"AggregateResults":null,"Errors":null}

我尝试使用:

field: "Data.ProductId",

代替:

field: "ProductId",

在 JavaScript 代码中无济于事。

4

1 回答 1

1

如果要使用 ToDataSourceResult,则应使用 ASP.NET MVC 包装器。文档中提供了更多信息:http ://docs.kendoui.c​​om/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/ajax-binding

于 2013-06-12T19:00:22.450 回答