Apr 13, 2018

Kendo Grid Binding Issue.. Multiple issues..


I was working on a Asp.Net MVC App on my current assignment where I stumbled on to a queer issue and though I should blog it for future reference which will be helpful for me or others. I had a Kendo Grid which I have to bind to a collection of Client objects sent from the Controller Action. The Controller Name is "ClientController" and the Action is "GetClients". Since it will be a the client ajax call, I am returning a JSon serialized collection. The codes looked like this.. 1. The cshtml code:
  @(Html.Kendo().Grid()
          .Name("grid")
          .Events(model => model.DetailInit("detailInit"))
          .Columns(columns =>
          {
              columns.Bound(model => model.ClientID).Width(25);
              columns.Bound(model => model.Name).Width(120);
              columns.Bound(model => model.Alias).Width(50);
          })
          .DataSource(dataSource =>
              dataSource.Ajax().Read(read => read.Action("GetClients", "Client"))
          )
          .ClientDetailTemplateId("client-template")
    )



    


    
2. The Controller code:
 public ActionResult GetClients([DataSourceRequest]DataSourceRequest request)
        {
           using (var db = new CMSDBEntities())
            {
                IQueryable clients = db.Clients
                    .Include(c => c.ClientContacts )
                    .Include(c => c.Projects)
                    .OrderBy(c => c.Name);
                DataSourceResult result = clients.ToDataSourceResult(request);
                return Json(result);
            }
        }
I was getting this error when I ran the code