/// <summary> /// Renders page link. /// </summary> /// <param name="htmlHelper">This is an HtmlHelper extension method.</param> /// <param name="pageLinkViewModel">Contains all of the information required to render a page link.</param> /// <returns>MvcHtmlString containing page link.</returns> public static IHtmlContent PageLink(this IHtmlHelper htmlHelper, PageLinkViewModel pageLink) { // If page ID not specified, then render link to the current page (this might be the case on a special administration page, where PageId is not set) if (pageLink.Page.PageId == 0) { string pathAndQuery = string.Format("{0}{1}", htmlHelper.ViewContext.HttpContext.Request.Path, htmlHelper.ViewContext.HttpContext.Request.QueryString); string pageLinkHtml = string.Format("<a href=\"{0}\">{1}</a>", pathAndQuery, htmlHelper.Encode(pageLink.LinkText)); return(new HtmlString(pageLinkHtml)); } // Otherwise, render link to page specified if (pageLink.Page.ParentPageId == null) { return(htmlHelper.RouteLink(pageLink.LinkText, "HomePage", pageLink.RouteValues, pageLink.HtmlAttributes)); } else { IWebHelperService webHelperService = (IWebHelperService)htmlHelper.ViewContext.HttpContext.RequestServices.GetService(typeof(IWebHelperService)); RouteValueDictionary routeValueDictionary = pageLink.RouteValues == null ? new RouteValueDictionary() : new RouteValueDictionary(pageLink.RouteValues); RouteValueDictionary htmlAttributesDictionary = pageLink.HtmlAttributes == null ? new RouteValueDictionary() : new RouteValueDictionary(pageLink.HtmlAttributes); routeValueDictionary.Add("pageid", pageLink.Page.PageId); routeValueDictionary.Add("description", webHelperService.UrlFriendly(pageLink.Description)); return(htmlHelper.RouteLink(pageLink.LinkText, "ReadPage", routeValueDictionary, (IDictionary <string, object>)htmlAttributesDictionary)); } }
public IActionResult CreateLinks(PageLinkViewModel model) { if (!ModelState.IsValid) { return(View(model)); } _db.PageLinks.AddCustom(model); _db.SaveChanges(); return(RedirectToAction("PageLink")); }
/// <summary> /// Renders page link. /// </summary> /// <param name="htmlHelper">This is an HtmlHelper extension method.</param> /// <param name="page">The page whose link is rendered.</param> /// <param name="linkText">Text that should appear on link.</param> /// <param name="description">SEO text that is displayed just before query string.</param> /// <param name="routeValues">Route values that should be added to the link.</param> /// <param name="htmlAttributes">Html attributes that should be applied to anchor tag.</param> /// <returns>MvcHtmlString containing page link.</returns> public static IHtmlContent PageLink(this IHtmlHelper htmlHelper, Page page, string linkText, string description, object routeValues, object htmlAttributes = null) { // Construct page link info from method arguments PageLinkViewModel pageLink = new PageLinkViewModel { Description = description, HtmlAttributes = htmlAttributes, LinkText = linkText, Page = page, RouteValues = routeValues }; // And return resulting HTML return(PageLink(htmlHelper, pageLink)); }
private IList <IPageLink> GetPageHierarchyPageLinks(Page page) { bool firstPage = true; IList <IPageLink> pageLinks = new List <IPageLink>(); while (page != null) { PageLinkViewModel pageLink = new PageLinkViewModel { Description = page.Name, LinkText = firstPage ? ElementResource.PageHeaderHomeBreadcrumbLabel : page.Name, Page = page }; pageLinks.Add(pageLink); page = page.ChildPages.Count == 1 ? page.ChildPages[0] : null; firstPage = false; } return(pageLinks); }
private PageViewModel createDefaultPageViewModel(page currentPage) { PageViewModel model = new PageViewModel(); model.titre = currentPage.titre; model.description = currentPage.description; model.id_projet = currentPage.id_projet; IEnumerable <page> pages = db.projets.Find(currentPage.id_projet).pages.OrderBy(p => p.numero); IList <PageLinkViewModel> pagesLinks = new List <PageLinkViewModel>(); foreach (page p in pages) { PageLinkViewModel link = new PageLinkViewModel(); link.titre = p.titre; link.page_url = "/pages/Details/" + p.id_page; if (currentPage.id_page == p.id_page) { link.isCurrent = true; } else { link.isCurrent = false; } pagesLinks.Add(link); } model.pages = pagesLinks; model.sections = currentPage.sections.OrderBy(s => s.ordre); model.page = new page(); model.page.id_page = currentPage.id_page; model.page.id_projet = currentPage.id_projet; model.page.numero = pages.Max(p => p.numero) + 1; return(model); }