Tarek.M
Tarek.M

Reputation: 1

ASP.NET MVC paging large volumes of data using LINQ

I have large volumes of data (50000 rows), I want to display my data in a table.

Since the large volumes of data, I want to create custom pagination (for example at application startup display 10 record then when the user click page 2 another 10 records loaded from database and displayed).

Any ideas? or best practices to create this pagination and research?

Thanks in advance.

Upvotes: 0

Views: 956

Answers (2)

Sunny Verma
Sunny Verma

Reputation: 107

You can pass your pageNumber and pageSize to the server side logic and get only a number of records from DB.

var customers = dbContext.Customers.FindAll().Skip((pageNumber - 1) * pageSize).Take(pageNumber).ToList();

And pageNumber should be always greater than 0.

Upvotes: 1

user10163992
user10163992

Reputation:

It's a very easy stuff...go through below link. If you have customer data then use the following type logic

 double pageCount = (double)((decimal)entities.Customers.Count() / Convert.ToDecimal(maxRows));
            customerModel.PageCount = (int)Math.Ceiling(pageCount);

Use the following link for more detail

https://www.aspsnippets.com/Articles/Server-Side-Paging-using-Entity-Framework-in-ASPNet-MVC.aspx

Upvotes: 0

Related Questions