public IActionResult Doctors(DoctorFilter filter) { ViewData["CurPage"] = "1"; IEnumerable <Doctors> doctors = null; if (filter.doctorName != null) { filter.currentPage = 1; ViewData["DoctorFilter"] = filter.doctorName; doctors = _repository.GetDoctorByName(filter.doctorName); } else { doctors = _repository.GetAllDoctors(); } if (doctors.Count() % 6 != 0) { ViewBag.LastPageNumber = ((doctors.Count() / 6) + 1).ToString(); } else { ViewBag.LastPageNumber = (doctors.Count() / 6).ToString(); } List <Doctors> x; if (filter.currentPage != 1) { x = doctors.Skip((filter.currentPage - 1) * 6).Take(6).ToList(); ViewBag.CurPageNumber = filter.currentPage.ToString(); ViewBag.NextPageNumber = (filter.currentPage + 1).ToString(); ViewBag.PreviousPageNumber = (filter.currentPage - 1).ToString(); } else { x = doctors.Take(6).ToList(); ViewBag.CurPageNumber = "1"; ViewBag.NextPageNumber = 2; } return(View(x)); }