Search code examples
c#razorasp.net-coretelerikasp.net-core-mvc

Telerik - cannot populate Grid with data


I'm trying to populate my Grid with Json data, which I gets from my controller. I have set breakpoints and checked that the data is returned correctly but Grid isn't filled somehow.

Controller :

[Route("/api/list/getAll")]
[HttpPost]
public IActionResult GetList()
{
    var result = _ListService.GetAll();
    if (result == null || result.Count == 0)
        return NotFound();

    return Json(result);
}

Razor :

@(Html.Kendo().Grid<Model>()
    .Name("grid")
    .Columns(columns => {
        columns.Bound(c => c.Name).Width(140);
    })
     .Scrollable()
     .Sortable()
     .Pageable(pageable => pageable
                    .Refresh(true)
                    .PageSizes(true)
                    .ButtonCount(5))
     .DataSource(dataSource => dataSource
                .Ajax()
                .Read(read => read.Action("GetList", "controller")))
    )

Model has much more fields but I just put only Name for test purposes. But this isn't filled anyway.

I have no idea what I'm doing wrong there is no errors, page just loading and Grid isn't filled.

//EDIT I thought type of return data might be a case (Pascal or Camel case), tested that as well and it isn't :/

Even tried to change what my method in controller return. Changed from IActionResult just to my Model, doesn't work as well.


Solution

  • Solution :

    public IActionResult GetList([DataSourceRequest] DataSourceRequest request)
    {
        return Json(_Service.GetAll().ToDataSourceResult(request));
    }
    

    Cannot explain why this work and my controller's method doesn't.