I have set up API for articles that whenever i do articles().count() it display 10 articles only. Thst y i am using skip to get another 10 for next page. so i want to do somthing that addes 10 to skip to get next 10 articles.
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
I m using SQL server as a data source. I have records of articles in to data base and one of my senior created external API (REST) to get the data from data base through that API. and at a time i can get 10 articles as a display. so he has setup parameters
name skip on that API for paging. So When ever i want to display articles i have to increase skip by 10 and it will load in to next page. (Just like paging but i have to use skip for paging straight from API not in the C#)
Please help me, i m new to it and need some idea to do somthing like this.
ashkorat
Member
7 Points
55 Posts
Create paging using skip - straight from API (RESTful) in MVC3
Jun 14, 2012 08:13 PM|LINK
Hello Guys,
I am trying to do paging using skip parameters from my external API (Rest).
for e.g. i have top parameter for displaying 10 articles on one page (MAX = 10) and to display next page i have to use skip parametes like
if top =10 and skip = 0 then it will page to first page
if top = 10 and skip = 10 then it will page to next page
if top = 10 and skip = 20 then it will page to third page and so on.
Please help me if possible to solve this problem.
Thanks.
BrockAllen
All-Star
27530 Points
4905 Posts
MVP
Re: Create paging using skip - straight from API (RESTful) in MVC3
Jun 14, 2012 08:46 PM|LINK
Something like this:
public ActionResult Index(int page = 1) { if (page < 1) page = 1; int pageSize = 5; var totRows = _repository.GetProducts().Count(); var totalPages = (int)Math.Ceiling(totRows / ((1.0)*pageSize)); if (page > totalPages) page = totalPages; int skip = (page - 1) * pageSize; var list = _repository.GetProducts().OrderBy(x=>x.ProductID).Skip(skip).Take(pageSize); var vm = new ProductIndexViewModel { Products = list, CurrentPage = page, TotalPages = totalPages, }; return View("Index", vm); }DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
ashkorat
Member
7 Points
55 Posts
Re: Create paging using skip - straight from API (RESTful) in MVC3
Jun 14, 2012 09:03 PM|LINK
I have set up API for articles that whenever i do articles().count() it display 10 articles only. Thst y i am using skip to get another 10 for next page. so i want to do somthing that addes 10 to skip to get next 10 articles.
ashkorat
Member
7 Points
55 Posts
Re: Create paging using skip - straight from API (RESTful) in MVC3
Jun 15, 2012 01:19 PM|LINK
Anyone, please help me out to find solution.
Thanks.
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: Create paging using skip - straight from API (RESTful) in MVC3
Jun 16, 2012 02:16 PM|LINK
Web API has built-in support for this,
http://www.asp.net/web-api/overview/web-api-routing-and-actions/paging-and-querying
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
ashkorat
Member
7 Points
55 Posts
Re: Create paging using skip - straight from API (RESTful) in MVC3
Jun 18, 2012 01:08 PM|LINK
Thanks Imran for reply. I will have a look.
But do you know how can i do it using custom paramerters like skip and top?
MisterFantas...
Participant
1335 Points
380 Posts
Re: Create paging using skip - straight from API (RESTful) in MVC3
Jun 18, 2012 01:11 PM|LINK
Which is the datasource you are trying with ?
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: Create paging using skip - straight from API (RESTful) in MVC3
Jun 18, 2012 01:41 PM|LINK
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
ashkorat
Member
7 Points
55 Posts
Re: Create paging using skip - straight from API (RESTful) in MVC3
Jun 18, 2012 01:49 PM|LINK
I m using SQL server as a data source. I have records of articles in to data base and one of my senior created external API (REST) to get the data from data base through that API. and at a time i can get 10 articles as a display. so he has setup parameters name skip on that API for paging. So When ever i want to display articles i have to increase skip by 10 and it will load in to next page. (Just like paging but i have to use skip for paging straight from API not in the C#)
Please help me, i m new to it and need some idea to do somthing like this.
Thanks.