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.