I’ve got the following C# code in an MVC3 Controller Action.
public ActionResult MyDocuments(int Page)
{
int start = (Page==1?1:(Page-1)*4);
int end = (Page==1?4:start + 4);
// start parameter begins at 1
Archive docs = mps.GetArchive(start, end);
ViewBag.docs = docs;
if (docs.Rows.Count() < 4)
{
ViewBag.lastPage = 1;
}
else
{
ViewBag.lastPage = 0;
}
ViewBag.pagenum = Page;
return View();
}
The issue I have is that it always starts the next page with the last entry from the previous page.
What am I doing wrong here? I do not know how many pages I will have, I only need to check the number returned in the docs object to see if it is < 4, then I set the ViewBag.lastPage value to disable the next btn in my View and the ViewBag.pagenum sets the pagenum value in the View to the current page number.
I suspect that your
mps.GetArchive(start, end)method is returning all records betweenstartandendinclusive. Normally the end value should be excluded.If you can’t change how the method works, call it as
mps.GetArchive(start, end - 1).