I have a following problem. I want to do nice paging and I do not want to download all records from WebService to my application.
Controller code:
public ActionResult Vacations(int? page)
{
int pageNumber = page ?? 1;
int quantity = 5;
using (MyWebService.MyWebServiceClient client = new MyWebService.MyWebServiceClient())
{
var vacations = client.GetUserAbsence(SessionManager.CurrentToken, quantity, pageNumber);
var onePageOfVacations = vacations.ToPagedList(pageNumber, quantity);
ViewBag.OnePageOfVacations = onePageOfVacations;
}
return View();
}
View Code:
<h2>Vacations</h2>
<div>
<table class="table tablesorter table-striped">
<thead>
<tr>
<th>Data od</th>
<th>Data do</th>
<th>Ilość dni</th>
</tr>
</thead>
<tbody>
@{
foreach (var v in ViewBag.OnePageOfVacations)
{
<tr>
<td>@v.From_Date</td>
<td>@v.To_Date</td>
<td>@v.Element_Name</td>
</tr>
}
}
</tbody>
<tfoot>
<tr>
<th>Data od</th>
<th>Data do</th>
<th>Ilość dni</th>
</tr>
</tfoot>
</table>
</div>
<!-- output a paging control that lets the user navigation to the previous page, next page, etc -->
@Html.PagedListPager((IPagedList)ViewBag.OnePageOfVacations, page => Url.Action("Vacations", new { page }))
I have a method in my webservice "GetUserAbsence()" which return to my only that number of records which I need. Now I have only one page and I cannot show other results. There is my question - how to connect this solution with PagedList or maybe how to create new paging on this solution?