public async Task <IActionResult> Index(int criteria, int?page) { ViewData["Header"] = "BlogApp"; ApplicationUser user = _userManager.GetUserAsync(HttpContext.User).Result; ViewBag.Message = $"Welcome {user.UserName}!"; var posts = _homePageService.GetAllPosts(); //switch by criteria switch (criteria) { case 0: posts = posts.OrderByDescending(service => service.PostedAt); break; case 1: posts = posts.OrderBy(service => service.PostedAt); break; case 2: posts = posts.OrderBy(service => service.Headline); break; case 3: posts = posts.OrderBy(service => service.UserName); break; } int pageSize = 5; ViewBag.SortingCriteria = criteria; return(View(await PaginatedList <Post> .CreateAsync(posts, page ?? 1, pageSize))); }