I have the below list made from my database which will bring back x
number results. I would like to split the result into list of 15 which will have List<List<SubjectModel>>
split list model.
I would like to know who I can do this, as there may not complete spilt as 15 as the final will have less. Also on MVC if I was to create a paging effect how can this be done by calling a diffent index of data to be loaded or will I have to go to the server each time.
I presume that I will have to have a parial page within a page.
List<SubjectModel> model = new List<SubjectModel>();
Generally you can use the .Skip() and .Take() LINQ methods in the following way:
.Skip(pageSize * pageNumber - 1).Take(pageSize)
I recommend do not fetch all, then split, instead do a real paging using the methods above. When using those methods against a real O/R mapper like Entity Framework, it will translate to your RDBMS's SQL.
You can use action method parameters in your controller to know what page was requested. Your pageSize could be a constant or a configuration value.
You can start learn the whole concept by googling: [implement paging in asp.net mvc]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.