Mithrilhall
Mithrilhall

Reputation: 1502

Kendo grid is showing json data instead of the actual grid

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.

enter image description here

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()
)

Upvotes: 1

Views: 3538

Answers (1)

GP24
GP24

Reputation: 877

You need to update the return command to:

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

Upvotes: 3

Related Questions