This is a migrated thread and some comments may be shown as answers.

Cannot populate Grid with JsonData

2 Answers 457 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adrian
Top achievements
Rank 1
Adrian asked on 22 Aug 2018, 01:51 PM

Hello, 

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.

2 Answers, 1 is accepted

Sort by
0
Adrian
Top achievements
Rank 1
answered on 23 Aug 2018, 07:31 AM

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

0
Konstantin Dikov
Telerik team
answered on 27 Aug 2018, 07:47 AM
H Adrian,

The ToDataSourceResult method is what modifies the data to the format that the Grid expects. More information about the AJAX binding could be found in the following help article;

Best Regards,
Konstantin Dikov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Adrian
Top achievements
Rank 1
Answers by
Adrian
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or