1 namespace System.Web.Mvc.Html { 2 using System; 3 using System.Collections.Generic; 4 using System.Web.Mvc.Resources; 5 using System.Web.Routing; 6 7 public static class LinkExtensions { ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName)8 public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName) { 9 return ActionLink(htmlHelper, linkText, actionName, null /* controllerName */, new RouteValueDictionary(), new RouteValueDictionary()); 10 } 11 ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues)12 public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues) { 13 return ActionLink(htmlHelper, linkText, actionName, null /* controllerName */, new RouteValueDictionary(routeValues), new RouteValueDictionary()); 14 } 15 ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues, object htmlAttributes)16 public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues, object htmlAttributes) { 17 return ActionLink(htmlHelper, linkText, actionName, null /* controllerName */, new RouteValueDictionary(routeValues), HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); 18 } 19 ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, RouteValueDictionary routeValues)20 public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, RouteValueDictionary routeValues) { 21 return ActionLink(htmlHelper, linkText, actionName, null /* controllerName */, routeValues, new RouteValueDictionary()); 22 } 23 ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)24 public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes) { 25 return ActionLink(htmlHelper, linkText, actionName, null /* controllerName */, routeValues, htmlAttributes); 26 } 27 ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName)28 public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName) { 29 return ActionLink(htmlHelper, linkText, actionName, controllerName, new RouteValueDictionary(), new RouteValueDictionary()); 30 } 31 ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes)32 public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes) { 33 return ActionLink(htmlHelper, linkText, actionName, controllerName, new RouteValueDictionary(routeValues), HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); 34 } 35 ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)36 public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes) { 37 if (String.IsNullOrEmpty(linkText)) { 38 throw new ArgumentException(MvcResources.Common_NullOrEmpty, "linkText"); 39 } 40 return MvcHtmlString.Create(HtmlHelper.GenerateLink(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection, linkText, null/* routeName */, actionName, controllerName, routeValues, htmlAttributes)); 41 } 42 ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, string protocol, string hostName, string fragment, object routeValues, object htmlAttributes)43 public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, string protocol, string hostName, string fragment, object routeValues, object htmlAttributes) { 44 return ActionLink(htmlHelper, linkText, actionName, controllerName, protocol, hostName, fragment, new RouteValueDictionary(routeValues), HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); 45 } 46 ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)47 public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes) { 48 if (String.IsNullOrEmpty(linkText)) { 49 throw new ArgumentException(MvcResources.Common_NullOrEmpty, "linkText"); 50 } 51 return MvcHtmlString.Create(HtmlHelper.GenerateLink(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection, linkText, null /* routeName */, actionName, controllerName, protocol, hostName, fragment, routeValues, htmlAttributes)); 52 } 53 RouteLink(this HtmlHelper htmlHelper, string linkText, object routeValues)54 public static MvcHtmlString RouteLink(this HtmlHelper htmlHelper, string linkText, object routeValues) { 55 return RouteLink(htmlHelper, linkText, new RouteValueDictionary(routeValues)); 56 } 57 RouteLink(this HtmlHelper htmlHelper, string linkText, RouteValueDictionary routeValues)58 public static MvcHtmlString RouteLink(this HtmlHelper htmlHelper, string linkText, RouteValueDictionary routeValues) { 59 return RouteLink(htmlHelper, linkText, routeValues, new RouteValueDictionary()); 60 } 61 RouteLink(this HtmlHelper htmlHelper, string linkText, string routeName)62 public static MvcHtmlString RouteLink(this HtmlHelper htmlHelper, string linkText, string routeName) { 63 return RouteLink(htmlHelper, linkText, routeName, (object)null /* routeValues */ ); 64 } 65 RouteLink(this HtmlHelper htmlHelper, string linkText, string routeName, object routeValues)66 public static MvcHtmlString RouteLink(this HtmlHelper htmlHelper, string linkText, string routeName, object routeValues) { 67 return RouteLink(htmlHelper, linkText, routeName, new RouteValueDictionary(routeValues)); 68 } 69 RouteLink(this HtmlHelper htmlHelper, string linkText, string routeName, RouteValueDictionary routeValues)70 public static MvcHtmlString RouteLink(this HtmlHelper htmlHelper, string linkText, string routeName, RouteValueDictionary routeValues) { 71 return RouteLink(htmlHelper, linkText, routeName, routeValues, new RouteValueDictionary()); 72 } 73 RouteLink(this HtmlHelper htmlHelper, string linkText, object routeValues, object htmlAttributes)74 public static MvcHtmlString RouteLink(this HtmlHelper htmlHelper, string linkText, object routeValues, object htmlAttributes) { 75 return RouteLink(htmlHelper, linkText, new RouteValueDictionary(routeValues), HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); 76 } 77 RouteLink(this HtmlHelper htmlHelper, string linkText, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)78 public static MvcHtmlString RouteLink(this HtmlHelper htmlHelper, string linkText, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes) { 79 return RouteLink(htmlHelper, linkText, null /* routeName */, routeValues, htmlAttributes); 80 } 81 RouteLink(this HtmlHelper htmlHelper, string linkText, string routeName, object routeValues, object htmlAttributes)82 public static MvcHtmlString RouteLink(this HtmlHelper htmlHelper, string linkText, string routeName, object routeValues, object htmlAttributes) { 83 return RouteLink(htmlHelper, linkText, routeName, new RouteValueDictionary(routeValues), HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); 84 } 85 RouteLink(this HtmlHelper htmlHelper, string linkText, string routeName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)86 public static MvcHtmlString RouteLink(this HtmlHelper htmlHelper, string linkText, string routeName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes) { 87 if (String.IsNullOrEmpty(linkText)) { 88 throw new ArgumentException(MvcResources.Common_NullOrEmpty, "linkText"); 89 } 90 return MvcHtmlString.Create(HtmlHelper.GenerateRouteLink(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection, linkText, routeName, routeValues, htmlAttributes)); 91 } 92 RouteLink(this HtmlHelper htmlHelper, string linkText, string routeName, string protocol, string hostName, string fragment, object routeValues, object htmlAttributes)93 public static MvcHtmlString RouteLink(this HtmlHelper htmlHelper, string linkText, string routeName, string protocol, string hostName, string fragment, object routeValues, object htmlAttributes) { 94 return RouteLink(htmlHelper, linkText, routeName, protocol, hostName, fragment, new RouteValueDictionary(routeValues), HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); 95 } 96 RouteLink(this HtmlHelper htmlHelper, string linkText, string routeName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)97 public static MvcHtmlString RouteLink(this HtmlHelper htmlHelper, string linkText, string routeName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes) { 98 if (String.IsNullOrEmpty(linkText)) { 99 throw new ArgumentException(MvcResources.Common_NullOrEmpty, "linkText"); 100 } 101 return MvcHtmlString.Create(HtmlHelper.GenerateRouteLink(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection, linkText, routeName, protocol, hostName, fragment, routeValues, htmlAttributes)); 102 } 103 } 104 } 105