public ActionResult UserWorks(int sectionID, int workSectionID, int?pageIndex) { if (!pageIndex.HasValue) { return(RedirectToAction(() => UserWorks(sectionID, workSectionID, 1))); } var index = pageIndex.Value - 1; var works = UserWorkService.GetAll().IsActive() .Where(uw => uw.Section_ID == sectionID); var model = new UserWorksVM { Section = SectionService.GetByPK(sectionID), }; if (workSectionID != 0) { model.WorkSection = UserWorkSectionService.GetByPK(workSectionID); works = works.Where(uw => uw.WorkSectionID == workSectionID); } model.UserWorks = works.OrderByDescending(uw => uw.UserWorkID) .ToPagedList(index, 10); return(View(model)); }