I am learning MVC. I'm creating a simple website for demo, which stores products in Database and shows them to the user 10 per page. Now, how do I fetch "NEXT" 10/20 items from the database? I thought of adding auto-increment column to table and then fetching items on its basis. Is it the right way? Also I am keeping record of how many items have been shown to the user by getting an int value as parameter to the Controller function, Products(int id). Is it the right way? I mean will it work if user is on 5th page(hence id==5) and refreshes the page?(or will it set id back to 0?).
Asked
Active
Viewed 58 times
0
-
1http://stackoverflow.com/questions/496470/paging-sorting-grids-with-asp-net-mvc – Neil Thompson Mar 27 '13 at 11:19
-
Thnx :-) It solves the problem . I hope answer below will help some other day. – vish213 Mar 27 '13 at 11:47
1 Answers
0
you can use linq queries to fetch number of items in a table. you can pass number of item, start index. then the query will be like this
var nextProduct = myProducts.Skip(100).Take(10);
it will return 10 items from 101 to 110.
Fetching data based on id is not a good idea. because if u delete any record there will be a difference in the count and id. so you can take using the above code concept

felix Antony
- 1,450
- 14
- 28