In this article I am going to explain how to create simple paging in mvc.
Sometimes you need to improve performance showing data use paging. In asp.net the grid view control allows you create wizard paging, but in mvc you don’t access it, and always programmers spend a lot of times in it. Now I am going to explain a simple way for paging with minimal code.
Sometimes you need to improve performance showing data use paging. In asp.net the grid view control allows you create wizard paging, but in mvc you don’t access it, and always programmers spend a lot of times in it. Now I am going to explain a simple way for paging with minimal code.
First create a model called Product,
- public class Product
- {
- public int Id { get; set; }
- public string Name { get; set; }
- public List<Product> GetList
- {
- get
- {
- return new List<Product>()
- {
- new Product() { Id = 1, Name = "p1" },
- new Product() { Id = 2, Name = "p2" },
- new Product() { Id = 3, Name = "p3" },
- new Product() { Id = 4, Name = "p4" },
- new Product() { Id = 5, Name = "p5" },
- new Product() { Id = 6, Name = "p6" },
- new Product() { Id = 7, Name = "p7" },
- new Product() { Id = 8, Name = "p8" },
- new Product() { Id = 9, Name = "p9" },
- new Product() { Id = 10, Name = "p10" },
- };
- }
- }
- }
To install MVC 4 Paging, run the following command in the Package Manager Console.
Install-Package PagedList.Mvc -Version 4.0.0.
Next create a controller called Home,
Ahmed NaveedPosted Jul 25, 2022, 7:04 PM
Hi, This line in Index of HomeController: var model = Product.GetList.ToList().ToPagedList(pageNumber, pageSize); gives an error "An object reference is required for the non-static field, method or property 'Product.GetList' " Is there a typo in your code?