I have a Kendo grid that I largely copied from a co-worker (the difference being that they use different tables as their source) and his works. He used a dynamic source instead of a model.
When I access the page, the grid doesn't appear. The ReadCustomerNotes action has a data table with data, so that's not the problem. I added a try-catch block and am now getting the error "Cannot perform runtime binding on a null reference".
I couldn't find anything online dealing with this error and a Kendo Grid using a dynamic source. How can I find out where the null reference is? Is there something I can put in the catch block to show what is causing the error?
Here's my code:
AdminCustomerNotes.cshtml
@{
  ViewBag.Title = "AdminCustomerNotes";
 }
@using (Html.BeginForm("AdminCustomerNotes", "Admin"))
{
 @(Html.Kendo().Grid<dynamic>()
 .Name("Grid")
 .Columns(columns =>
  {
   foreach (System.Data.DataColumn column in Model.Columns)
   {
    switch (column.ColumnName)
    {
     case "customerNotes":
      columns.Bound(column.ColumnName);
     break;
    }
   }
  })
  .Pageable(x => x.PageSizes(new int[] { 10, 20, 30, 50 }).Refresh(true))
  .Sortable()
  .Filterable()
  .Groupable()
  .DataSource(dataSource => dataSource
  .Ajax()
  .Model(model =>
   {
    var id = Model.PrimaryKey[0].ColumnName;
    model.Id(id);
   })
  .Read(read => read.Action("ReadCustomerNotes", "Admin", new { customerID = int.Parse(ViewBag.compId.ToString()) })))
  .AutoBind(true)
 )
}
catch (Exception ex)
{
 @ex.Message;
}
}
AdminController.cs
    public ActionResult ReadCustomerNotes([DataSourceRequest] DataSourceRequest request, int customerID)
    {
        var customerNotes = CustomerNotes(false, customerID);
        return Json(customerNotes.ToDataSourceResult(request));
    }
    private DataTable CustomerNotes(bool init, int customerID)
    {
        try
        {
            return Rep.GetCustomerNotesByCustomerID(init ? 0 : customerID);
        }
        catch (Exception exception)
        {
            return null;
        }
    }
Repository.cs
public DataTable GetCustomerNotesByCustomerID(int customerID)
{
  try
  {
   var dt = new DataTable();
   dt.Columns.Add("customerNotesID", typeof(int));
   dt.Columns.Add("customerNotesDate", typeof(string));
   dt.Columns.Add("customerNotes", typeof(string));
   dt.PrimaryKey = new[]
   {
    dt.Columns["customerNotesID"]
   };
   var qry =
    from customerNotes in dat.tblCoNoteses
    where (
           customerNotes.CompId == customerID
          )
    select new
    {
        customerNotes.CoNotesId
     ,  customerNotes.CompId
     ,  customerNotes.Note 
     ,  customerNotes.AddBy
     , customerNotes.AddDate
     };
     foreach (var itm in qry)
     {
       var row = dt.NewRow();
       row["customerNotesID"] = itm.CoNotesId;
       row["customerNotesDate"] = string.IsNullOrEmpty(itm.AddDate.ToString()) ? "" : DateTime.Parse(itm.AddDate.ToString()).ToShortDateString();
       row["customerNotes"] = itm.Note;
       dt.Rows.Add(row);
     }
    return dt;
  }
 catch (Exception exception)
 {
   return null;
 }
}
 
    