In order to implement the jQuery DataTables plugin, we first need to create a new view that will list data inside an HTML table. For this example, we'll create a view that lists customers from the Northwind Traders database. For this, complete the following steps:
In Visual Studio, add a new controller class called
CustomersController.cs
.We've implemented a dependency injection in our project, so we'll add a constructor to the class that will automatically set the reference to the database context with the following code:
public CustomersController(ApplicationDbContext context) { _context = context; }
The
_context
object is a local field declared inside the class as follows:private readonly ApplicationDbContext _context;
Add a new method called
Index
to the controller. This method returns anActionResult
object to the controller. Add the following code to it that will pass a list of customer objects to the view:public ActionResult Index()...