Kendo网格显示json数据而不是实际网格

时间:2013-01-25 21:54:52

标签: asp.net-mvc json kendo-ui kendo-grid

我正在尝试在Kendo弹出窗口中启动一个Kendo网格,但不是网格显示,我得到了json数据。

enter image description here

这是我控制器的代码:

[HttpGet]
    public ActionResult Read([DataSourceRequest]DataSourceRequest request, int id)
    {
        var model = Service.FindOne("Cashflows", x => x.Id == id);
        var cashflows = new List<flows>();

        foreach (var cf in model.CashFlows)
        {
            var flow = new flows
            {
                Id = cf.Id,
                AssetId = cf.Id,
                MortgageValue = cf.MortgageValue,
                Year = cf.Year
            };
            cashflows.Add(flow);
        }

        var result = cashflows.ToDataSourceResult(request);

        return Json(result, JsonRequestBehavior.AllowGet);
    }

这就是我在Kendo View中所拥有的。

@(Html.Kendo().Grid<ViewModels.Finance.flows>()
.Name("Grid")
.Columns(columns =>
{
    columns.Bound(p => p.Id);
    columns.Bound(p => p.AssetId);
    columns.Bound(p => p.Year);
    columns.Bound(p => p.MortgageValue);
})
.DataSource(dataSource => dataSource
    .Ajax()
    .Read(read => read.Action("Read", "Finance"))
    .ServerOperation(false)
    .PageSize(5)
)
.Pageable()
)

1 个答案:

答案 0 :(得分:3)

您需要将return命令更新为:

return Json(result.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);