Kendo grid is showing json data instead of the actual grid

让人想犯罪 __ 提交于 2019-12-11 04:23:43

问题


I'm trying to launch a Kendo grid in a Kendo popup Window but instead of the grid showing, I'm getting the json data.

This is the code from my controller:

[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);
    }

This is what I have in my 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:


You need to update the return command to:

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


来源:https://stackoverflow.com/questions/14530969/kendo-grid-is-showing-json-data-instead-of-the-actual-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!