// 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.AspNet.Mvc.Routing;
namespace Microsoft.AspNet.Mvc
{
public static class UrlHelperExtensions
{
///
/// Generates a fully qualified or absolute URL for an action method.
///
/// The fully qualified or absolute URL to an action method.
public static string Action(this IUrlHelper helper)
{
if (helper == null)
{
throw new ArgumentNullException(nameof(helper));
}
return helper.Action(
action: null,
controller: null,
values: null,
protocol: null,
host: null,
fragment: null);
}
///
/// Generates a fully qualified or absolute URL for an action method by using the specified action name.
///
/// The name of the action method.
/// The fully qualified or absolute URL to an action method.
public static string Action(this IUrlHelper helper, string action)
{
if (helper == null)
{
throw new ArgumentNullException(nameof(helper));
}
return helper.Action(action, controller: null, values: null, protocol: null, host: null, fragment: null);
}
///
/// Generates a fully qualified or absolute URL for an action method by using the specified action name,
/// and route values.
///
/// The name of the action method.
/// An object that contains route values.
/// The fully qualified or absolute URL to an action method.
public static string Action(this IUrlHelper helper, string action, object values)
{
if (helper == null)
{
throw new ArgumentNullException(nameof(helper));
}
return helper.Action(action, controller: null, values: values, protocol: null, host: null, fragment: null);
}
///
/// Generates a fully qualified or absolute URL for an action method by using the specified action name,
/// and controller name.
///
/// The name of the action method.
/// The name of the controller.
/// The fully qualified or absolute URL to an action method.
public static string Action(this IUrlHelper helper, string action, string controller)
{
if (helper == null)
{
throw new ArgumentNullException(nameof(helper));
}
return helper.Action(action, controller, values: null, protocol: null, host: null, fragment: null);
}
///
/// Generates a fully qualified or absolute URL for an action method by using the specified action name,
/// controller name, and route values.
///
/// The name of the action method.
/// The name of the controller.
/// An object that contains route values.
/// The fully qualified or absolute URL to an action method.
public static string Action(this IUrlHelper helper, string action, string controller, object values)
{
if (helper == null)
{
throw new ArgumentNullException(nameof(helper));
}
return helper.Action(action, controller, values, protocol: null, host: null, fragment: null);
}
///
/// Generates a fully qualified or absolute URL for an action method by using the specified action name,
/// controller name, route values, and protocol to use.
///
/// The name of the action method.
/// The name of the controller.
/// An object that contains route values.
/// The protocol for the URL, such as "http" or "https".
/// The fully qualified or absolute URL to an action method.
public static string Action(
this IUrlHelper helper,
string action,
string controller,
object values,
string protocol)
{
if (helper == null)
{
throw new ArgumentNullException(nameof(helper));
}
return helper.Action(action, controller, values, protocol, host: null, fragment: null);
}
///
/// Generates a fully qualified or absolute URL for an action method by using the specified action name,
/// controller name, route values, protocol to use, and host name.
///
/// The name of the action method.
/// The name of the controller.
/// An object that contains route values.
/// The protocol for the URL, such as "http" or "https".
/// The host name for the URL.
/// The fully qualified or absolute URL to an action method.
public static string Action(
this IUrlHelper helper,
string action,
string controller,
object values,
string protocol,
string host)
{
if (helper == null)
{
throw new ArgumentNullException(nameof(helper));
}
return helper.Action(action, controller, values, protocol, host, fragment: null);
}
///
/// Generates a fully qualified or absolute URL for an action method by using the specified action name,
/// controller name, route values, protocol to use, host name and fragment.
///
/// The name of the action method.
/// The name of the controller.
/// An object that contains route values.
/// The protocol for the URL, such as "http" or "https".
/// The host name for the URL.
/// The fragment for the URL.
/// The fully qualified or absolute URL to an action method.
public static string Action(
this IUrlHelper helper,
string action,
string controller,
object values,
string protocol,
string host,
string fragment)
{
if (helper == null)
{
throw new ArgumentNullException(nameof(helper));
}
return helper.Action(new UrlActionContext()
{
Action = action,
Controller = controller,
Host = host,
Values = values,
Protocol = protocol,
Fragment = fragment
});
}
///
/// Generates a fully qualified or absolute URL for the specified route values.
///
/// An object that contains route values.
/// The fully qualified or absolute URL.
public static string RouteUrl(this IUrlHelper helper, object values)
{
if (helper == null)
{
throw new ArgumentNullException(nameof(helper));
}
return helper.RouteUrl(routeName: null, values: values, protocol: null, host: null, fragment: null);
}
///
/// Generates a fully qualified or absolute URL for the specified route name.
///
/// The name of the route that is used to generate URL.
/// The fully qualified or absolute URL.
public static string RouteUrl(this IUrlHelper helper, string routeName)
{
if (helper == null)
{
throw new ArgumentNullException(nameof(helper));
}
return helper.RouteUrl(routeName, values: null, protocol: null, host: null, fragment: null);
}
///
/// Generates a fully qualified or absolute URL for the specified route values by
/// using the specified route name.
///
/// The name of the route that is used to generate URL.
/// An object that contains route values.
/// The fully qualified or absolute URL.
public static string RouteUrl(this IUrlHelper helper, string routeName, object values)
{
if (helper == null)
{
throw new ArgumentNullException(nameof(helper));
}
return helper.RouteUrl(routeName, values, protocol: null, host: null, fragment: null);
}
///
/// Generates a fully qualified or absolute URL for the specified route values by
/// using the specified route name, and protocol to use.
///
/// The name of the route that is used to generate URL.
/// An object that contains route values.
/// The protocol for the URL, such as "http" or "https".
/// The fully qualified or absolute URL.
public static string RouteUrl(
this IUrlHelper helper,
string routeName,
object values,
string protocol)
{
if (helper == null)
{
throw new ArgumentNullException(nameof(helper));
}
return helper.RouteUrl(routeName, values, protocol, host: null, fragment: null);
}
///
/// Generates a fully qualified or absolute URL for the specified route values by
/// using the specified route name, protocol to use, and host name.
///
/// The name of the route that is used to generate URL.
/// An object that contains route values.
/// The protocol for the URL, such as "http" or "https".
/// The host name for the URL.
/// The fully qualified or absolute URL.
public static string RouteUrl(
this IUrlHelper helper,
string routeName,
object values,
string protocol,
string host)
{
if (helper == null)
{
throw new ArgumentNullException(nameof(helper));
}
return helper.RouteUrl(routeName, values, protocol, host, fragment: null);
}
///
/// Generates a fully qualified or absolute URL for the specified route values by
/// using the specified route name, protocol to use, host name and fragment.
///
/// The name of the route that is used to generate URL.
/// An object that contains route values.
/// The protocol for the URL, such as "http" or "https".
/// The host name for the URL.
/// The fragment for the URL.
/// The fully qualified or absolute URL.
public static string RouteUrl(
this IUrlHelper helper,
string routeName,
object values,
string protocol,
string host,
string fragment)
{
if (helper == null)
{
throw new ArgumentNullException(nameof(helper));
}
return helper.RouteUrl(new UrlRouteContext()
{
RouteName = routeName,
Values = values,
Protocol = protocol,
Host = host,
Fragment = fragment
});
}
}
}