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

Issue Binding Grid via AJAX

1 Answer 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Support
Top achievements
Rank 1
Support asked on 04 Jul 2013, 09:40 PM
Hi,

I am having an issue binding a KendoUI Grid to a JSON data source using MVC 4. I have the following setup:

  1. One controller called DashboardController.cs
  2. The DashboardController.cs contains an action called Reports_Read which has the following code
public ActionResult Reports_Read()
{
    List<Report> reports = new List<Report>();
    reports.Add(new Report
    {
        ReportId = Guid.NewGuid(),
        Title = "Lorem Ipsum",
        BillToClient = "Frosty Stevens",
        MainRecipientContact = "Dusty McLaren",
        NextReportDue = DateTime.Now.AddDays(7),
        PrimaryConsultant = "Sprinkles O'Reilly",
        ServiceCategoryCode = "ABC"
    });
 
    reports.Add(new Report
    {
        ReportId = Guid.NewGuid(),
        Title = "Lorem Ipsum",
        BillToClient = "Harry Houdini",
        MainRecipientContact = "David Blaine",
        NextReportDue = DateTime.Now.AddDays(7),
        PrimaryConsultant = "Dynamo",
        ServiceCategoryCode = "EFG"
    });
 
    return Json(reports, JsonRequestBehavior.AllowGet);
}
3. The Index.aspx contains the KendoUI Grid as follows:

<%:Html.Kendo().Grid<ProcareGroup.Crm.Web.Models.Report>()
.Name("grid")
.DataSource(ds => ds
    .Ajax()
    .ServerOperation(false)
    .Read(r => {
        r.Action("Reports_Read", "Dashboard");
    }))
.Columns(c => {
    c.Bound(r => r.Title);
    c.Bound(r => r.PrimaryConsultant);
    c.Bound(r => r.ServiceCategoryCode);
    c.Bound(r => r.BillToClient);
    c.Bound(r => r.NextReportDue);
})
.Pageable()
.Sortable()
%>
The debugger hits my breakpoint set inside the Reports_Read action when I launch the page, however nothing is bound to the grid. What am I missing here? I have tried setting AutoBind to true but this does not work.

1 Answer, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 05 Jul 2013, 06:29 AM
You are missing the call to ToDataSourceResult extension method which will format the response/JSON in a way that the DataSource can parse on client.

For more details see step 8 in the following article: Grid Ajax Binding

Regards,
Nikolay Rusev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Support
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question
or