Пример #1
0
        public static IHtmlString GeneratePageUrl(UrlHelper urlHelper, Site site, Page page, object values, FrontRequestChannel channel)
        {
            RouteValueDictionary routeValues = RouteValuesHelpers.GetRouteValues(values);

            page = page.AsActual();

            if (page == null)
            {
                return(new HtmlString(""));
            }
            if (page.Route != null && !string.IsNullOrEmpty(page.Route.ExternalUrl))
            {
                return(new HtmlString(page.Route.ExternalUrl));
            }

            var pageRoute = page.Route.ToMvcRoute();

            routeValues = RouteValuesHelpers.MergeRouteValues(pageRoute.Defaults, routeValues);

            var routeVirtualPath = pageRoute.GetVirtualPath(urlHelper.RequestContext, routeValues);

            if (routeVirtualPath == null)
            {
                throw new InvalidPageRouteException(page);
            }
            //string contentUrl = routeVirtualPath.VirtualPath;//don't decode the url. why??
            //if do not decode the url, the route values contains Chinese character will cause bad request.
            string contentUrl = HttpUtility.UrlDecode(routeVirtualPath.VirtualPath);
            string pageUrl    = contentUrl;

            if (!string.IsNullOrEmpty(contentUrl) || (string.IsNullOrEmpty(pageUrl) && !page.IsDefault))
            {
                pageUrl = Kooboo.Web.Url.UrlUtility.Combine(page.VirtualPath, contentUrl);
            }
            if (string.IsNullOrEmpty(pageUrl))
            {
                pageUrl = urlHelper.Content("~/");
            }
            else
            {
                pageUrl = HttpUtility.UrlDecode(
                    urlHelper.RouteUrl("Page", new { PageUrl = new HtmlString(pageUrl) }));
            }
            var url = FrontUrlHelper.WrapperUrl(pageUrl, site, channel);

            return(url);
        }
Пример #2
0
        public virtual IHtmlString ViewLink(object linkText, string viewName, object routeValues, object htmlAttributes)
        {
            var htmlValues = RouteValuesHelpers.GetRouteValues(htmlAttributes);

            string url = this.PageContext.FrontUrl.ViewUrl(viewName, routeValues).ToString();


            TagBuilder builder = new TagBuilder("a")
            {
                InnerHtml = linkText != null?HttpUtility.HtmlEncode(linkText) : string.Empty
            };

            builder.MergeAttributes <string, object>(htmlValues);
            builder.MergeAttribute("href", url);
            var html = new HtmlString(builder.ToString(TagRenderMode.Normal));

            return(html);
        }
Пример #3
0
        public virtual IHtmlString PageLink(object linkText, string urlMapKey, object routeValues, object htmlAttributes)
        {
#if Page_Trace
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
#endif
            var  htmlValues = RouteValuesHelpers.GetRouteValues(htmlAttributes);
            Page page;

            string url = this.PageContext.FrontUrl.PageUrl(urlMapKey, routeValues, out page).ToString();

            page = page.AsActual();

            var innerHtml = "";
            if (linkText == null)
            {
                innerHtml = page.LinkText;
            }
            else
            {
                innerHtml = HttpUtility.HtmlEncode(linkText);
            }
            TagBuilder builder = new TagBuilder("a")
            {
                InnerHtml = innerHtml
            };
            builder.MergeAttributes <string, object>(htmlValues);
            builder.MergeAttribute("href", url);
            if (page != null && page.Route != null)
            {
                builder.MergeAttribute("target", page.Route.LinkTarget.ToString());
            }
            var html = new HtmlString(builder.ToString(TagRenderMode.Normal));

#if Page_Trace
            stopwatch.Stop();
            HttpContext.Current.Response.Write(string.Format("PageLink,{0}.</br>", stopwatch.Elapsed));
#endif
            return(html);
        }
Пример #4
0
        //Optional parameter does not support NVelocity
        public virtual IHtmlString Pager(object model, object routeValues, PagerOptions options, object htmlAttributes)
        {
            options = options ?? new PagerOptions();

            if ((model is DataRulePagedList))
            {
                options.PageIndexParameterName = ((DataRulePagedList)model).PageIndexParameterName;
            }

            var pagedList = (IPagedList)model;

            var builder = new CmsPagerBuilder
                          (
                this,
                pagedList,
                options,
                RouteValuesHelpers.GetRouteValues(routeValues),
                RouteValuesHelpers.GetRouteValues(htmlAttributes)
                          );

            return(new HtmlString(builder.RenderPager().ToString()));
        }