My index action loads all the products from the database and sends them to the view. I have confirmed that the products are being pulled successfully.
The problem arises when the view is loaded, as it displays a message indicating there are no data entries in the table.
Controller
public class InventoryController : Controller
{
private readonly IRepository<Product> _productContext;
public InventoryController(IRepository<Product> productContext)
{
_productContext = productContext;
}
// GET: Inventory
public ActionResult Index()
{
List<Product> Products = _productContext.Collection().ToList();
return View(Products);
}
}
View With script
@model IEnumerable<SuperStockpile.Core.Models.Product>
@{
ViewBag.Title = "Inventory";
}
<h2>Inventory</h2>
<p>
@Html.ActionLink("Add New Product","Create","Inventory",null,new {@class = "btn btn-primary"})
</p>
<table class="table table-hover table-bordered" id="products">
<thead>
<tr>
<th>@Html.DisplayNameFor(model => model.UPC)</th>
<th>@Html.DisplayNameFor(model => model.SKU)</th>
<th>@Html.DisplayNameFor(model => model.Cost)</th>
<th>@Html.DisplayNameFor(model => model.DiscountPercent)</th>
<th>@Html.DisplayNameFor(model => model.ItemCode)</th>
<th>@Html.DisplayNameFor(model => model.CreatedAt)</th>
</tr>
</thead>
<tbody></tbody>
</table>
@section scripts
{
<script>
$(document).ready(function() {
$('#products').DataTable();
});
</script>
}
I seem to be encountering an issue where the data is not displaying correctly in my view. The data table appears correctly but without any content. Any assistance or suggestions would be greatly appreciated.