IUrlHelper Interface

Defines the contract for the helper to build URLs for ASP.NET MVC within an application.

Namespace
Microsoft.AspNetCore.Mvc
Assemblies
  • Microsoft.AspNetCore.Mvc.Abstractions

Syntax

public interface IUrlHelper
interface Microsoft.AspNetCore.Mvc.IUrlHelper

Methods

Action(Microsoft.AspNetCore.Mvc.Routing.UrlActionContext)

Generates a fully qualified or absolute URL specified by Microsoft.AspNetCore.Mvc.Routing.UrlActionContext for an action method, which contains action name, controller name, route values, protocol to use, host name, and fragment.

Arguments:actionContext (Microsoft.AspNetCore.Mvc.Routing.UrlActionContext) – The context object for the generated URLs for an action method.
Return type:System.String
Returns:The fully qualified or absolute URL to an action method.
string Action(UrlActionContext actionContext)
Content(System.String)

Converts a virtual (relative) path to an application absolute path.

Arguments:contentPath (System.String) – The virtual path of the content.
Return type:System.String
Returns:The application absolute path.
string Content(string contentPath)
IsLocalUrl(System.String)

Returns a value that indicates whether the URL is local. A URL with an absolute path is considered local if it does not have a host/authority part. URLs using virtual paths (‘~/’) are also local.

Arguments:url (System.String) – The URL.
Return type:System.Boolean
Returns:<code>true</code> if the URL is local; otherwise, <code>false</code>.
bool IsLocalUrl(string url)

Generates an absolute URL using the specified route name and values.

Arguments:
  • routeName (System.String) – The name of the route that is used to generate the URL.
  • values (System.Object) – An object that contains the route values.
Return type:

System.String

Returns:

The generated absolute URL.

string Link(string routeName, object values)
RouteUrl(Microsoft.AspNetCore.Mvc.Routing.UrlRouteContext)

Generates a fully qualified or absolute URL specified by Microsoft.AspNetCore.Mvc.Routing.UrlRouteContext, which contains the route name, the route values, protocol to use, host name and fragment.

Arguments:routeContext (Microsoft.AspNetCore.Mvc.Routing.UrlRouteContext) – The context object for the generated URLs for a route.
Return type:System.String
Returns:The fully qualified or absolute URL.
string RouteUrl(UrlRouteContext routeContext)

Properties

Microsoft.AspNetCore.Mvc.IUrlHelper.ActionContext

Gets the Microsoft.AspNetCore.Mvc.IUrlHelper.ActionContext for the current request.

Return type:Microsoft.AspNetCore.Mvc.ActionContext
ActionContext ActionContext { get; }