0

I have just changed a View with IEnumerable<model> to IEnumerable<ViewModel> which triggered this error notification. Have found some similar issues here. Also checked http://datatables.net/tn/4 to understand more on this but was not able to resolve this issue. When I reverted back to using using Model instead of ViewModel it works properly which baffles me. Since the same properties of Model and ViewModel has.

View:

    @model IEnumerable<ERPLite.Models.DeliveryScheduleVM>


@section Scripts{
    <script>
        $(function () {

            $('#TableId').DataTable({
                'paging': true,
                'lengthChange': false,
                'searching': true,
                'ordering': true,
                'info': true,
                'autoWidth': false,
                "scrollX": true,
                'order': [[0, 'desc']]//orderby desc
            })
        })
    </script>
}

<div class="box">

    <!-- /.box-header -->
    <div class="box-body">
        <table id="TableId" class="table table-bordered table-striped">
            <thead>
                <tr>
                    <th hidden="hidden">@Html.DisplayNameFor(model => model.ID)</th>

                    <th>@Html.DisplayNameFor(model => model.ProductName)</th>

                    <th>@Html.DisplayNameFor(model => model.Quantity)</th>

                   <th>Actions</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model)
                {
                    <tr>
                        <td hidden="hidden">
                            @Html.DisplayFor(modelItem => item.ID)
                        </td>

                        <td>
                            @Html.DisplayFor(modelItem => item.ProductName)
                        </td>

                        <td>
                            @Html.DisplayFor(modelItem => item.Quantity)
                        </td>


                    </tr>
                }

            </tbody>

        </table>
    </div>
    <!-- /.box-body -->
</div>

Action Method:

  public ActionResult Index()
        {
            var deliverySchedules = db.DeliverySchedules.ToList();
            var deliverySchedulesVMList = new List<DeliveryScheduleVM>();
            foreach(var item in deliverySchedules)
            {
                var deliveryScheduleVM = new DeliveryScheduleVM();
                deliveryScheduleVM.ID = item.ID;
                deliveryScheduleVM.ProductID = item.ProductID;
                var product = db.Products.Find(item.ProductID);
                deliveryScheduleVM.ProductName = product.ProductName;
                deliveryScheduleVM.Quantity = item.Quantity;
                deliverySchedulesVMList.Add(deliveryScheduleVM);
            }
            return View(deliverySchedulesVMList);
        }

Warning full description:

DataTables warning: table id=TableId - Requested unknown parameter '9' for row 0. For more information about this error, please see http://datatables.net/tn/4

Appreciate any help. thanks in advance.

user2695433
  • 2,013
  • 4
  • 25
  • 44
  • The parameter seems to be an integer, which possibly you've table columns more than specified in HTML markup or amount of table cells doesn't satisfy `DataTable` requirements. – Tetsuya Yamamoto Nov 08 '17 at 06:28

1 Answers1

0

The number of header columns and body columns was not matching which turned out to be the issue. There was no <td></td> in the <tbody> for <th>Actions</th> in the Markup. That was really a silly mistake which I overlooked while changing the columns. Posting here since I was checking the Data /Column part as per the nature of the warning message.

user2695433
  • 2,013
  • 4
  • 25
  • 44