title: Records Not Displaying in jquery.datatables using server side pagination processing
body: <p>i am trying to get jquery.datatables working using server side processing and pagination. I used the following example article as a guide because its close to the version VS2017 that i am using- </p>
  
  <p><a href="https://www.c-sharpcorner.com/article/filtering-jquery-data-table-server-side-using-mvc-and-entity-framework/" rel="nofollow noreferrer">https://www.c-sharpcorner.com/article/filtering-jquery-data-table-server-side-using-mvc-and-entity-framework/</a></p>
  
  <p>When I run the application i get the following error:</p>
  
  <p>DataTables warning: table id=tblrtr - Requested unknown parameter 'Id' for row 0, column 0. For more information about this error, please see <a href="http://datatables.net/tn/4" rel="nofollow noreferrer">http://datatables.net/tn/4</a></p>
  
  <p>and an empty grid that shows 10 blank lines and the right page count.</p>
  
  <p>I have debugged the code and it finds all the records and values, and indeed the finalresult variable does return the contents of the 10 rows- but they dont seem to make it to the datatable grid.</p>
  
  <p>Here is the controller code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Threading.Tasks;
  using Microsoft.AspNetCore.Mvc;
  using Microsoft.AspNetCore.Mvc.Rendering;
  using Microsoft.EntityFrameworkCore;
  using RTMGMTTest.Models;
  
  namespace RTMGMTTest.Controllers
  {
      public class ReportsToRecordsController : Controller
      {
          private readonly RTMGMTContext _context;
  
          public ReportsToRecordsController(RTMGMTContext context)
          {
              _context = context;
          }
  
          // GET: ReportsToRecords
          public async Task&lt;IActionResult&gt; Index()
          {
              //return View(await _context.ReportsToRecords.ToListAsync());
              return View();
          }
  
  
          [HttpPost]
          public JsonResult RTRList(DTParameters param)
          {
  
              int TotalCount = 0;
              var filtered = this.GetRTRFiltered(param.Search.Value, param.SortOrder, param.Start, param.Length, out TotalCount);
  
              var RTRList = filtered.Select(o =&gt; new ReportsToRecords()
              {
  
                  Id = o.Id,
                  ReportingId = o.ReportingId,
                  Title = o.Title,
                  Name = o.Name,
                  ReportsToId = o.ReportsToId,
                  EmployeeId = o.EmployeeId
              });
  
  
  
              DTResult&lt;ReportsToRecords&gt; finalresult = new DTResult&lt;ReportsToRecords&gt;
              {
                  draw = param.Draw,
                  data = RTRList.ToList(),
                  recordsFiltered = TotalCount,
                  recordsTotal = filtered.Count
  
              };
  
              return Json(finalresult);
  
          }
  </code></pre>
  
  <p>and</p>
  
  <p>//for server side processing</p>
  
  <pre><code>public List&lt;ReportsToRecords&gt; GetRTRFiltered(string search, string sortOrder, int start, int length, out int TotalCount)
  {
  
  
      var result = _context.ReportsToRecords.Where(p =&gt; (search == null 
          || (p.ReportingId != null &amp;&amp; p.ReportingId.ToLower().Contains(search.ToLower())
          || p.Title != null &amp;&amp; p.Title.ToLower().Contains(search.ToLower())
          || p.Name != null &amp;&amp; p.Name.ToLower().Contains(search.ToLower())
          || p.ReportsToId != null &amp;&amp; p.ReportsToId.ToLower().Contains(search.ToLower())
          || p.EmployeeId!= null &amp;&amp; p.EmployeeId.ToLower().Contains(search.ToLower())
          ))).ToList();
  
      TotalCount = result.Count;
  
      result = result.Skip(start).Take(length).ToList();
  
  
      switch (sortOrder)
      {
          case "ReportingId":
              result = result.OrderBy(a =&gt; a.ReportingId).ToList();
              break;
          case "Title":
              result = result.OrderBy(a =&gt; a.Title).ToList();
              break;
          case "Name":
              result = result.OrderBy(a =&gt; a.Name).ToList();
              break;
          case "ReportsToId":
              result = result.OrderBy(a =&gt; a.ReportsToId).ToList();
              break;
          case "EmployeeId":
              result = result.OrderBy(a =&gt; a.EmployeeId).ToList();
              break;
          default:
              result = result.AsQueryable().ToList();
              break;
      }
      return result.ToList();
  }
  </code></pre>
  
  <p>The view page looks as follows:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>@model IEnumerable&lt;RTMGMTTest.Models.ReportsToRecords&gt;
  
  @{
      ViewData["Title"] = "Index";
      Layout = "~/Views/Shared/_Layout.cshtml";
  }
  
  &lt;h2&gt;Index&lt;/h2&gt;
  
  &lt;p&gt;
      &lt;a asp-action="Create"&gt;Create New&lt;/a&gt;
  &lt;/p&gt;
  &lt;script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.3.1.min.js"&gt;&lt;/script&gt;
  &lt;link rel="stylesheet" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" /&gt;
  &lt;script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"&gt;&lt;/script&gt;
  
  &lt;script&gt;
  
      $(document).ready(function () {
  
          if ($.fn.DataTable.isDataTable('#tblrtr')) {
              $('#tblrtr').dataTable().fnDestroy();
              $('#tblrtr').dataTable().empty();
  
          }
  
          var complete = $('#tblrtr').DataTable(
              {
                  "serverSide": true,
                  "destroy": true,
                  "processing": true,
                  "ajax":
                      {
                          url: "/ReportsToRecords/RTRList",
                          method: "POST"
                      },
                  "columns": [
                      { "data": "Id"},
                      { "data": "ReportingId" },
                      { "data": "Title" },
                      { "data": "Name" },
                      { "data": "ReportsToId" },
                      { "data": "EmployeeId" }
  
                  ]
              }
  
          );
  
          /// Following code is for filter input to apply filter only on Enter
          var itm = $("#tblrtr_filter input")
  
          itm.unbind();
          itm.keyup(function (e) {
              //enter or tab
              if (e.keyCode == 13) {
                  complete.search(this.value).draw();
              }
          });
  
  
      });
  &lt;/script&gt;
  &lt;table class="table" id="tblrtr"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  Id
              &lt;/th&gt;
              &lt;th&gt;
                  ReportingId
              &lt;/th&gt;
              &lt;th&gt;
                  Title
              &lt;/th&gt;
              &lt;th&gt;
                  Name
              &lt;/th&gt;
              &lt;th&gt;
                  ReportsToId
              &lt;/th&gt;
              &lt;th&gt;
                  EmployeeId
              &lt;/th&gt;
              &lt;th&gt;&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;&lt;/tbody&gt;
  &lt;/table&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Does anyone know what would cause the data returned from the controller to not display and cause the resulting message? Thanks.</p>