Pagination is used to divide content, usually lists, into separate pages. For example, when scaffolding a list view, the default scaffolding template generates a table that contains a row for each item in the collection you pass into the view. This is fine for small amounts of data, but if the list contains hundreds of items, your page will take a very long time to load. Ideally, we would like to split our list view into a manageable view that has five items per page. In the following screenshot, we've changed the Products page's table to use pagination:
The aforementioned view is accomplished using the PagedList.Mvc
NuGet package and completing the following steps:
To install it, run the following command inside the Visual Studio Package Manager Console:
Install-Package PagedList.Mvc
This command will add the necessary dependencies to your project. Next, open your controller action and change its code to the following:
public ActionResult Index(int? page) { var models = _context...