public IActionResult Index(string text, string tagName, int?pageSize, int?pageNumber) { List <Tag> tagListFilter = _TagCollection.GetTagList(); tagListFilter = tagListFilter.DistinctBy(x => x.Name).ToList(); SelectList tagSelectListFilter = new SelectList(tagListFilter, "Name", "Name", tagName ?? ""); SelectList pageSizeSelectList = new SelectList(new[] { new { ID = "5", Name = "5" }, new { ID = "10", Name = "10" }, new { ID = "15", Name = "15" }, new { ID = "25", Name = "25" }, new { ID = "50", Name = "50" }, new { ID = "100", Name = "100" }, }, "ID", "Name", pageSize ?? 5); List <Post> postList = _PostCollection.GetPostListWithFilters(text, tagName); List <PostViewModel> postViewModelList = _Mapper.Map <List <PostViewModel> >(postList); foreach (PostViewModel postViewModel in postViewModelList) { List <Tag> tagList = _TagCollection.GetTagListFromPostId(postViewModel.Post_Id); postViewModel.TagList = _Mapper.Map <List <TagViewModel> >(tagList); } postViewModelList = postViewModelList.OrderByDescending(x => x.Posted).ToList(); PaginatedList <PostViewModel> postViewModelPaginatedList = PaginatedList <PostViewModel> .CreateList(postViewModelList, pageSize ?? 5, pageNumber ?? 1); string metaTags = ""; foreach (Tag tag in tagListFilter) { metaTags = $"{metaTags} {tag.Name}"; } ViewData["meta"] = $"Blog {metaTags}"; ViewData["title"] = "Blog"; ViewData["body"] = "body-blog"; ViewData["current_filter_text"] = text; ViewData["prev_disabled"] = !postViewModelPaginatedList.HasPreviousPage ? "disabled" : ""; ViewData["next_disabled"] = !postViewModelPaginatedList.HasNextPage ? "disabled" : ""; ViewBag.TagSelectListFilter = tagSelectListFilter; ViewBag.PageSizeSelectList = pageSizeSelectList; return(View(postViewModelPaginatedList)); }