Class UrlExtensions

Contains extension methods related to friendly urls for System.Web.Mvc.UrlHelper.

Inheritance
System.Object
UrlExtensions
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: EPiServer.Web.Mvc.Html
Assembly: EPiServer.dll
Version: 8.11.0
Syntax
public static class UrlExtensions

Methods

Renders a content link. Uses IContent.Name property as an anchor innerHTML

Declaration
public static MvcHtmlString ContentLink(this HtmlHelper htmlHelper, Url url)
Parameters
Type Name Description
System.Web.Mvc.HtmlHelper htmlHelper

The HTML helper

Url url

The URL

Returns
Type Description
System.Web.Mvc.MvcHtmlString

An anchor tag with the specified url and content name in innerHTML.

Renders a content link. Uses IContent.Name property as an anchor innerHTML

Declaration
public static MvcHtmlString ContentLink(this HtmlHelper htmlHelper, Url url, IDictionary<string, object> htmlAttributes)
Parameters
Type Name Description
System.Web.Mvc.HtmlHelper htmlHelper

The HTML helper

Url url

The URL

System.Collections.Generic.IDictionary<System.String, System.Object> htmlAttributes

The HTML attributes.

Returns
Type Description
System.Web.Mvc.MvcHtmlString

An anchor tag with the specified url and content name in innerHTML.

ContentUrl(UrlHelper, ContentReference)

Resolves an URL using routing for a specific ContentReference

Declaration
public static string ContentUrl(this UrlHelper urlHelper, ContentReference contentLink)
Parameters
Type Name Description
System.Web.Mvc.UrlHelper urlHelper

The URL helper instance that this method extends

ContentReference contentLink

The content reference to resolve

Returns
Type Description
System.String

The URL or an empty string

ContentUrl(UrlHelper, Url)

Resolves an URL using routing for a Url

Declaration
public static string ContentUrl(this UrlHelper urlHelper, Url url)
Parameters
Type Name Description
System.Web.Mvc.UrlHelper urlHelper

The URL helper instance that this method extends

Url url

The url to resolve

Returns
Type Description
System.String

The URL or an empty string

PageUrl(UrlHelper, String)

Legacy method: Returns the hierarchical URL representation of a classic URL.

Declaration
public static MvcHtmlString PageUrl(this UrlHelper urlHelper, string classicUrl)
Parameters
Type Name Description
System.Web.Mvc.UrlHelper urlHelper

The URL helper instance that this method extends.

System.String classicUrl

The classic URL that should be converted into an hierarchical URL.

The URL can be absolute or relative.

Returns
Type Description
System.Web.Mvc.MvcHtmlString

Depending on the value of classicUrl this method returns:

  • a hierarchical representation of classicUrl if it refers to a page in this application.
  • classicUrl if it refers to an external resource.
  • System.Web.Mvc.MvcHtmlString.Empty if classicUrl could not be converten into an URL.

Remarks

The string returned does not contain an anchor tag, it only contains the URL.

This method exists for legacy reasons, event though it returns a MvcHtmlString the output is not either HTML or encoded.

Exceptions
Type Condition
System.ArgumentException

classicUrl is null.

Declaration
public static MvcHtmlString UrlLink(this HtmlHelper htmlHelper, Url url)
Parameters
Type Name Description
System.Web.Mvc.HtmlHelper htmlHelper
Url url
Returns
Type Description
System.Web.Mvc.MvcHtmlString
Declaration
public static MvcHtmlString UrlLink(this HtmlHelper htmlHelper, Url url, string linkText)
Parameters
Type Name Description
System.Web.Mvc.HtmlHelper htmlHelper
Url url
System.String linkText
Returns
Type Description
System.Web.Mvc.MvcHtmlString

Returns an anchor tag with the specified url.

Declaration
public static MvcHtmlString UrlLink(this HtmlHelper htmlHelper, Url url, string linkText, IDictionary<string, object> htmlAttributes)
Parameters
Type Name Description
System.Web.Mvc.HtmlHelper htmlHelper

The HTML helper.

Url url

The URL.

System.String linkText

The link text.

System.Collections.Generic.IDictionary<System.String, System.Object> htmlAttributes

The HTML attributes.

Returns
Type Description
System.Web.Mvc.MvcHtmlString

An anchor tag with the specified url.

Exceptions
Type Condition
System.ArgumentNullException

url is null.