public ActionResult ViewDataOfTransDatabase(string sortorder, string currentFilter, string MonthSearch, int?page, string YearSearch, string searchString) { CCIRepository repository = CCIRepository.CreateRepository(); List <Transport> list = ViewDetails(); ViewBag.CurrentSort = sortorder; ViewBag.PhoneSortParm = String.IsNullOrEmpty(sortorder) ? "Phone_desc" : ""; if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; var transportdetails = from _model in list select _model; if (!String.IsNullOrEmpty(MonthSearch) && !String.IsNullOrEmpty(YearSearch)) { transportdetails = repository.GetMnthAndYear(MonthSearch, YearSearch); //transportdetails = transportdetails.Where(A => A.PresentDate.ToString().Contains(MonthSearch.ToString()) && A.PresentDate.ToString().Contains(YearSearch.ToString())); } else if (!String.IsNullOrEmpty(searchString)) { transportdetails = transportdetails.Where(A => A.Name.ToString().Contains(searchString.ToString())); } int pageSize = 5; int pageNumber = (page ?? 1); return(View(transportdetails.ToPagedList(pageNumber, pageSize))); }