Esempio n. 1
0
        /// <summary>
        /// Returns current url modified by parameters
        /// </summary>
        /// <param name="self">Url helper</param>
        /// <param name="with">Values to add or override</param>
        /// <param name="without">Values to remove if present</param>
        /// <returns>Url</returns>
        public static string Current(this UrlHelper self, object with = null, string[] without = null)
        {
            var routeValues = Current(self.RequestContext, with, without);

            // makes sure that "without" parameter works
            var urlHelper = new UrlHelper(RoutingExtensions.CreateFakeRequestContext("/"));

            return(urlHelper.Action(null, routeValues));
        }
Esempio n. 2
0
        /// <summary>
        /// Returns anchor element with current url of parent context modified by parameters
        /// </summary>
        /// <param name="self">Html helper</param>
        /// <param name="linkText">The inner text of anchor element</param>
        /// <param name="htmlAttributes">Additional html attributes</param>
        /// <param name="with">Values to add or override</param>
        /// <param name="without">Values to remove if present</param>
        /// <returns>Anchor element</returns>
        public static MvcHtmlString ParentCurrentLink(this HtmlHelper self, string linkText, object htmlAttributes, object with = null, string[] without = null)
        {
            var routeValues = ParentCurrent(self.ViewContext.RequestContext, with, without);

            // makes sure that "without" parameter works
            var urlHelper = new UrlHelper(RoutingExtensions.CreateFakeRequestContext("/"));

            TagBuilder builder = new TagBuilder("a");

            builder.InnerHtml = !string.IsNullOrEmpty(linkText) ? HttpUtility.HtmlEncode(linkText) : string.Empty;
            builder.MergeAttributes <string, object>(new RouteValueDictionary(htmlAttributes));
            builder.MergeAttribute("href", urlHelper.Action(null, routeValues));
            return(MvcHtmlString.Create(builder.ToString(TagRenderMode.Normal)));
        }