Esempio n. 1
0
        public ViewResult List(string category, int page)
        {
            List<Skill> skillsToDisplay = category == null ? _skillsRepository.Skills.ToList() : _skillsRepository.Skills.Where(s => s.Category == category).ToList();
            var pagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = skillsToDisplay.Count() };
            var viewModel = new SkillsListViewModel {
                                                        PagingInfo = pagingInfo,
                                                        SkillsToDisplay = skillsToDisplay.Skip((page - 1)*PageSize).Take(PageSize).Select(x => new SkillUiItem {Skill = x, Routes = new RouteValueDictionary(new {controller = "Skills", action = "Detail", category = !string.IsNullOrEmpty(category) ? category : null, skillName = x.Name})}).ToList(),
                                                        CurrentCategory = !string.IsNullOrEmpty(category) ? category : null
            };

            return View(viewModel);
        }
Esempio n. 2
0
        public static MvcHtmlString PageLinks(this HtmlHelper html, PagingInfo pagingInfo, Func<int, string> pageUrl)
        {
            StringBuilder result = new StringBuilder();
            for (int i = 1; i <= pagingInfo.TotalPages; i++)
            {
                TagBuilder tag = new TagBuilder("a"); // Construct an <a> tag

                tag.MergeAttribute("href", pageUrl(i));
                tag.InnerHtml = i.ToString();
                if (i == pagingInfo.CurrentPage)
                    tag.AddCssClass("selected");
                result.AppendLine(tag.ToString());
            }
            return MvcHtmlString.Create(result.ToString());
        }