public IActionResult Index(string currentPnFilter, string personalNr, DateTime?bDateStart, DateTime?currentdStartFilter, DateTime?bDateEnd, DateTime?currentdEndFilter, int?pageNumber) { if (personalNr != null || bDateStart != null || bDateEnd != null) { pageNumber = 1; } else { personalNr = currentPnFilter; bDateStart = currentdStartFilter; bDateEnd = currentdEndFilter; } ViewData["CurrentPnFilter"] = personalNr; var students = _unitOfWork.StudentRepository.Get(includeProperties: "Gender"); if (!String.IsNullOrWhiteSpace(personalNr)) { students = students.Where(c => c.PersonalNr.Contains(personalNr)); } if (bDateStart.HasValue) { students = students.Where(c => c.BirthDate >= bDateStart.Value); ViewData["CurrentdStartFilter"] = bDateStart.Value.ToString("yyyy-MM-dd"); } if (bDateEnd.HasValue) { students = students.Where(c => c.BirthDate <= bDateEnd.Value); ViewData["CurrentdEndFilter"] = bDateEnd.Value.ToString("yyyy-MM-dd"); } int pageSize = 5; return(View(PaginatedList <Student> .GetList(students, pageNumber ?? 1, pageSize))); }