I was trying to make Custom paging with LINQ. Everything is fine. But the Last page results previous page output values. I know because of this,
int skip = Math.Max(AC.rows * (AC.page - 1), 0); // Doing page -1.
But I need to know how can i make the logic purely to work with pagination. Pls someone guide me to do correct logic for this.
Code
var selectpending = CsA.CsAutoCompletes(AC, searchTerm);
var Tot = selectpending.Count();
int skip = Math.Max(AC.rows * (AC.page - 1), 0);
int totpages = Convert.ToInt32(Tot / AC.rows);
um = selectpending.Skip(skip).Take(AC.rows).ToList();
return Json(new
{
rows = um,
records = Tot,
page = AC.page,
total = totpages
}
, JsonRequestBehavior.AllowGet);
Totmay not be divisible byAC.Rows, so you should do something likeint totpages = (int)Math.Ceiling(((double)Tot)/ AC.Rows);