// GET: Home public ActionResult Index(int page = 1) { int totalRows = 0; List <Vehicle> vehicleList = _data.Page(page, ROWS_PER_PAGE, out totalRows); Pagination <Vehicle> objPagination = new Pagination <Vehicle>(); objPagination.Items = vehicleList; objPagination.PageNumber = page; objPagination.RowsPerPage = ROWS_PER_PAGE; objPagination.TotalRows = totalRows; objPagination.TotalPages = totalRows / ROWS_PER_PAGE; List <int> pagesList = GetPages(objPagination.TotalPages); ViewBag.Pages = pagesList; return(View(objPagination)); }
public Pagination <Vehicle> Page(int pageNumber, int rowsPerPage) { try { int totalRows = 0; List <Vehicle> vehicles = dataVehicles.Page(pageNumber, rowsPerPage, out totalRows); Pagination <Vehicle> pagination = new Pagination <Vehicle> { Items = vehicles, PageNumber = pageNumber, RowsPerPage = rowsPerPage, TotalPages = totalRows / rowsPerPage, TotalRows = totalRows }; return(pagination); } catch (Exception ex) { throw ex; } }