示例#1
0
        public static string Generate(RequestContext requestContext, NavigationRequest navigationItem, RouteValueDictionary routeValues)
        {
            if (requestContext == null)
                throw new ArgumentNullException("requestContext");
            if (navigationItem == null)
                throw new ArgumentNullException("navigationItem");

            var urlHelper = new UrlHelper(requestContext);
            string generatedUrl = null;

            if (!string.IsNullOrEmpty(navigationItem.RouteName))
            {
                generatedUrl = urlHelper.RouteUrl(navigationItem.RouteName, routeValues);
            }
            else if (!string.IsNullOrEmpty(navigationItem.ControllerName) && !string.IsNullOrEmpty(navigationItem.ActionName))
            {
                generatedUrl = urlHelper.Action(navigationItem.ActionName, navigationItem.ControllerName, routeValues, null, null);
            }
            else if (!string.IsNullOrEmpty(navigationItem.Url))
            {
                generatedUrl = navigationItem.Url.StartsWith("~/", StringComparison.Ordinal) 
                    ? urlHelper.Content(navigationItem.Url) 
                    : navigationItem.Url;
            }
            else if (routeValues.Any())
            {
                generatedUrl = urlHelper.RouteUrl(routeValues);
            }

            return generatedUrl;

        }
示例#2
0
        public static string Generate(RequestContext requestContext, NavigationRequest navigationItem)
        {
            var routeValues = new RouteValueDictionary();

            if (navigationItem.RouteValues.Any())
                routeValues.Merge(navigationItem.RouteValues);

            return Generate(requestContext, navigationItem, routeValues);
        }
示例#3
0
 public Link(ViewContext viewContext)
     : base(viewContext)
 {
     Encode = true;
     Navigation = new NavigationRequest();
 }
示例#4
0
 public Link(RequestContext requestContext)
     : base(requestContext)
 {
     Encode = true;
     Navigation = new NavigationRequest();
 }
示例#5
0
 public Link(HtmlHelper htmlHelper)
     : base(htmlHelper)
 {
     Encode = true;
     Navigation = new NavigationRequest();
 }