UrlHelper Class

An implementation of Microsoft.AspNetCore.Mvc.IUrlHelper that contains methods to build URLs for ASP.NET MVC within an application.

Namespace
Microsoft.AspNetCore.Mvc.Routing
Assemblies
  • Microsoft.AspNetCore.Mvc.Core

Syntax

public class UrlHelper : IUrlHelper
class Microsoft.AspNetCore.Mvc.Routing.UrlHelper

Constructors

UrlHelper(Microsoft.AspNetCore.Mvc.ActionContext)

Initializes a new instance of the Microsoft.AspNetCore.Mvc.Routing.UrlHelper class using the specified action context and action selector.

Arguments:actionContext (Microsoft.AspNetCore.Mvc.ActionContext) – The Microsoft.AspNetCore.Mvc.ActionContext for the current request.
public UrlHelper(ActionContext actionContext)

Methods

Action(Microsoft.AspNetCore.Mvc.Routing.UrlActionContext)
Return type:System.String
public virtual string Action(UrlActionContext actionContext)
Content(System.String)
Return type:System.String
public virtual string Content(string contentPath)
GenerateUrl(System.String, System.String, Microsoft.AspNetCore.Routing.VirtualPathData, System.String)

Generates the URL using the specified components.

Arguments:
Return type:

System.String

Returns:

The generated URL.

protected virtual string GenerateUrl(string protocol, string host, VirtualPathData pathData, string fragment)
GetVirtualPathData(System.String, Microsoft.AspNetCore.Routing.RouteValueDictionary)

Gets the Microsoft.AspNetCore.Routing.VirtualPathData for the specified route values by using the specified route name.

Arguments:
Return type:

Microsoft.AspNetCore.Routing.VirtualPathData

Returns:

The Microsoft.AspNetCore.Routing.VirtualPathData.

protected virtual VirtualPathData GetVirtualPathData(string routeName, RouteValueDictionary values)
IsLocalUrl(System.String)
Return type:System.Boolean
public virtual bool IsLocalUrl(string url)
Return type:System.String
public virtual string Link(string routeName, object values)
RouteUrl(Microsoft.AspNetCore.Mvc.Routing.UrlRouteContext)
Return type:System.String
public virtual string RouteUrl(UrlRouteContext routeContext)

Properties

Microsoft.AspNetCore.Mvc.Routing.UrlHelper.ActionContext
Return type:Microsoft.AspNetCore.Mvc.ActionContext
public ActionContext ActionContext { get; }
Microsoft.AspNetCore.Mvc.Routing.UrlHelper.AmbientValues
Return type:Microsoft.AspNetCore.Routing.RouteValueDictionary
protected RouteValueDictionary AmbientValues { get; }
Microsoft.AspNetCore.Mvc.Routing.UrlHelper.HttpContext
Return type:Microsoft.AspNetCore.Http.HttpContext
protected HttpContext HttpContext { get; }
Microsoft.AspNetCore.Mvc.Routing.UrlHelper.Router
Return type:Microsoft.AspNetCore.Routing.IRouter
protected IRouter Router { get; }