// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.AspNetCore.Html; namespace Microsoft.AspNetCore.Mvc.Rendering { /// /// Link-related extensions for . /// public static class HtmlHelperLinkExtensions { /// /// Returns an anchor (<a>) element that contains a URL path to the specified action. /// /// The instance this method extends. /// The inner text of the anchor element. Must not be null. /// The name of the action. /// A new containing the anchor element. public static IHtmlContent ActionLink( this IHtmlHelper helper, string linkText, string actionName) { if (helper == null) { throw new ArgumentNullException(nameof(helper)); } if (linkText == null) { throw new ArgumentNullException(nameof(linkText)); } return helper.ActionLink( linkText, actionName, controllerName: null, protocol: null, hostname: null, fragment: null, routeValues: null, htmlAttributes: null); } /// /// Returns an anchor (<a>) element that contains a URL path to the specified action. /// /// The instance this method extends. /// The inner text of the anchor element. Must not be null. /// The name of the action. /// /// An that contains the parameters for a route. The parameters are retrieved through /// reflection by examining the properties of the . This is typically /// created using initializer syntax. Alternatively, an /// instance containing the route /// parameters. /// /// A new containing the anchor element. public static IHtmlContent ActionLink( this IHtmlHelper helper, string linkText, string actionName, object routeValues) { if (helper == null) { throw new ArgumentNullException(nameof(helper)); } if (linkText == null) { throw new ArgumentNullException(nameof(linkText)); } return helper.ActionLink( linkText, actionName, controllerName: null, protocol: null, hostname: null, fragment: null, routeValues: routeValues, htmlAttributes: null); } /// /// Returns an anchor (<a>) element that contains a URL path to the specified action. /// /// The instance this method extends. /// The inner text of the anchor element. Must not be null. /// The name of the action. /// /// An that contains the parameters for a route. The parameters are retrieved through /// reflection by examining the properties of the . This is typically /// created using initializer syntax. Alternatively, an /// instance containing the route /// parameters. /// /// /// An that contains the HTML attributes for the element. Alternatively, an /// instance containing the HTML /// attributes. /// /// A new containing the anchor element. public static IHtmlContent ActionLink( this IHtmlHelper helper, string linkText, string actionName, object routeValues, object htmlAttributes) { if (helper == null) { throw new ArgumentNullException(nameof(helper)); } if (linkText == null) { throw new ArgumentNullException(nameof(linkText)); } return helper.ActionLink( linkText, actionName, controllerName: null, protocol: null, hostname: null, fragment: null, routeValues: routeValues, htmlAttributes: htmlAttributes); } /// /// Returns an anchor (<a>) element that contains a URL path to the specified action. /// /// The instance this method extends. /// The inner text of the anchor element. Must not be null. /// The name of the action. /// The name of the controller. /// A new containing the anchor element. public static IHtmlContent ActionLink( this IHtmlHelper helper, string linkText, string actionName, string controllerName) { if (helper == null) { throw new ArgumentNullException(nameof(helper)); } if (linkText == null) { throw new ArgumentNullException(nameof(linkText)); } return helper.ActionLink( linkText, actionName, controllerName, protocol: null, hostname: null, fragment: null, routeValues: null, htmlAttributes: null); } /// /// Returns an anchor (<a>) element that contains a URL path to the specified action. /// /// The instance this method extends. /// The inner text of the anchor element. Must not be null. /// The name of the action. /// The name of the controller. /// /// An that contains the parameters for a route. The parameters are retrieved through /// reflection by examining the properties of the . This is typically /// created using initializer syntax. Alternatively, an /// instance containing the route /// parameters. /// /// A new containing the anchor element. public static IHtmlContent ActionLink( this IHtmlHelper helper, string linkText, string actionName, string controllerName, object routeValues) { if (helper == null) { throw new ArgumentNullException(nameof(helper)); } if (linkText == null) { throw new ArgumentNullException(nameof(linkText)); } return helper.ActionLink( linkText, actionName, controllerName, protocol: null, hostname: null, fragment: null, routeValues: routeValues, htmlAttributes: null); } /// /// Returns an anchor (<a>) element that contains a URL path to the specified action. /// /// The instance this method extends. /// The inner text of the anchor element. Must not be null. /// The name of the action. /// The name of the controller. /// /// An that contains the parameters for a route. The parameters are retrieved through /// reflection by examining the properties of the . This is typically /// created using initializer syntax. Alternatively, an /// instance containing the route /// parameters. /// /// /// An that contains the HTML attributes for the element. Alternatively, an /// instance containing the HTML /// attributes. /// /// A new containing the anchor element. public static IHtmlContent ActionLink( this IHtmlHelper helper, string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes) { if (helper == null) { throw new ArgumentNullException(nameof(helper)); } if (linkText == null) { throw new ArgumentNullException(nameof(linkText)); } return helper.ActionLink( linkText, actionName, controllerName, protocol: null, hostname: null, fragment: null, routeValues: routeValues, htmlAttributes: htmlAttributes); } /// /// Returns an anchor (<a>) element that contains a URL path to the specified route. /// /// The instance this method extends. /// The inner text of the anchor element. Must not be null. /// /// An that contains the parameters for a route. The parameters are retrieved through /// reflection by examining the properties of the . This is typically /// created using initializer syntax. Alternatively, an /// instance containing the route /// parameters. /// /// A new containing the anchor element. public static IHtmlContent RouteLink( this IHtmlHelper htmlHelper, string linkText, object routeValues) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (linkText == null) { throw new ArgumentNullException(nameof(linkText)); } return htmlHelper.RouteLink( linkText, routeName: null, protocol: null, hostName: null, fragment: null, routeValues: routeValues, htmlAttributes: null); } /// /// Returns an anchor (<a>) element that contains a URL path to the specified route. /// /// The instance this method extends. /// The inner text of the anchor element. Must not be null. /// The name of the route. /// A new containing the anchor element. public static IHtmlContent RouteLink( this IHtmlHelper htmlHelper, string linkText, string routeName) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (linkText == null) { throw new ArgumentNullException(nameof(linkText)); } return htmlHelper.RouteLink( linkText, routeName, protocol: null, hostName: null, fragment: null, routeValues: null, htmlAttributes: null); } /// /// Returns an anchor (<a>) element that contains a URL path to the specified route. /// /// The instance this method extends. /// The inner text of the anchor element. Must not be null. /// The name of the route. /// /// An that contains the parameters for a route. The parameters are retrieved through /// reflection by examining the properties of the . This is typically /// created using initializer syntax. Alternatively, an /// instance containing the route /// parameters. /// /// A new containing the anchor element. public static IHtmlContent RouteLink( this IHtmlHelper htmlHelper, string linkText, string routeName, object routeValues) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (linkText == null) { throw new ArgumentNullException(nameof(linkText)); } return htmlHelper.RouteLink( linkText, routeName, protocol: null, hostName: null, fragment: null, routeValues: routeValues, htmlAttributes: null); } /// /// Returns an anchor (<a>) element that contains a URL path to the specified route. /// /// The instance this method extends. /// The inner text of the anchor element. Must not be null. /// /// An that contains the parameters for a route. The parameters are retrieved through /// reflection by examining the properties of the . This is typically /// created using initializer syntax. Alternatively, an /// instance containing the route /// parameters. /// /// /// An that contains the HTML attributes for the element. Alternatively, an /// instance containing the HTML /// attributes. /// /// A new containing the anchor element. public static IHtmlContent RouteLink( this IHtmlHelper htmlHelper, string linkText, object routeValues, object htmlAttributes) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (linkText == null) { throw new ArgumentNullException(nameof(linkText)); } return htmlHelper.RouteLink( linkText, routeName: null, protocol: null, hostName: null, fragment: null, routeValues: routeValues, htmlAttributes: htmlAttributes); } /// /// Returns an anchor (<a>) element that contains a URL path to the specified route. /// /// The instance this method extends. /// The inner text of the anchor element. Must not be null. /// The name of the route. /// /// An that contains the parameters for a route. The parameters are retrieved through /// reflection by examining the properties of the . This is typically /// created using initializer syntax. Alternatively, an /// instance containing the route /// parameters. /// /// /// An that contains the HTML attributes for the element. Alternatively, an /// instance containing the HTML /// attributes. /// /// A new containing the anchor element. public static IHtmlContent RouteLink( this IHtmlHelper htmlHelper, string linkText, string routeName, object routeValues, object htmlAttributes) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (linkText == null) { throw new ArgumentNullException(nameof(linkText)); } return htmlHelper.RouteLink( linkText, routeName, protocol: null, hostName: null, fragment: null, routeValues: routeValues, htmlAttributes: htmlAttributes); } } }