LinkExtensions Class (System.Web.Mvc.Html)

Switch View :
ScriptFree
.NET Framework Class Library
LinkExtensions Class

Represents support for HTML links in an application.

Inheritance Hierarchy

System.Object
  System.Web.Mvc.Html.LinkExtensions

Namespace:  System.Web.Mvc.Html
Assembly:  System.Web.Mvc (in System.Web.Mvc.dll)
Syntax

Visual Basic
<ExtensionAttribute> _
Public NotInheritable Class LinkExtensions
C#
public static class LinkExtensions
Visual C++
[ExtensionAttribute]
public ref class LinkExtensions abstract sealed
Methods

  Name Description
Public method Static member ActionLink(HtmlHelper, String, String) Returns an anchor element (a element) that contains the virtual path of the specified action.
Public method Static member ActionLink(HtmlHelper, String, String, Object) Returns an anchor element (a element) that contains the virtual path of the specified action.
Public method Static member ActionLink(HtmlHelper, String, String, String) Returns an anchor element (a element) that contains the virtual path of the specified action.
Public method Static member ActionLink(HtmlHelper, String, String, RouteValueDictionary) Returns an anchor element (a element) that contains the virtual path of the specified action.
Public method Static member ActionLink(HtmlHelper, String, String, Object, Object) Returns an anchor element (a element) that contains the virtual path of the specified action.
Public method Static member ActionLink(HtmlHelper, String, String, RouteValueDictionary, IDictionary<String, Object>) Returns an anchor element (a element) that contains the virtual path of the specified action.
Public method Static member ActionLink(HtmlHelper, String, String, String, Object, Object) Returns an anchor element (a element) that contains the virtual path of the specified action.
Public method Static member ActionLink(HtmlHelper, String, String, String, RouteValueDictionary, IDictionary<String, Object>) Returns an anchor element (a element) that contains the virtual path of the specified action.
Public method Static member ActionLink(HtmlHelper, String, String, String, String, String, String, Object, Object) Returns an anchor element (a element) that contains the virtual path of the specified action.
Public method Static member ActionLink(HtmlHelper, String, String, String, String, String, String, RouteValueDictionary, IDictionary<String, Object>) Returns an anchor element (a element) that contains the virtual path of the specified action.
Public method Static member RouteLink(HtmlHelper, String, Object) Returns an anchor element (a element) that contains the virtual path of the specified action.
Public method Static member RouteLink(HtmlHelper, String, String) Returns an anchor element (a element) that contains the virtual path of the specified action.
Public method Static member RouteLink(HtmlHelper, String, RouteValueDictionary) Returns an anchor element (a element) that contains the virtual path of the specified action.
Public method Static member RouteLink(HtmlHelper, String, Object, Object) Returns an anchor element (a element) that contains the virtual path of the specified action.
Public method Static member RouteLink(HtmlHelper, String, String, Object) Returns an anchor element (a element) that contains the virtual path of the specified action.
Public method Static member RouteLink(HtmlHelper, String, String, RouteValueDictionary) Returns an anchor element (a element) that contains the virtual path of the specified action.
Public method Static member RouteLink(HtmlHelper, String, RouteValueDictionary, IDictionary<String, Object>) Returns an anchor element (a element) that contains the virtual path of the specified action.
Public method Static member RouteLink(HtmlHelper, String, String, Object, Object) Returns an anchor element (a element) that contains the virtual path of the specified action.
Public method Static member RouteLink(HtmlHelper, String, String, RouteValueDictionary, IDictionary<String, Object>) Returns an anchor element (a element) that contains the virtual path of the specified action.
Public method Static member RouteLink(HtmlHelper, String, String, String, String, String, Object, Object) Returns an anchor element (a element) that contains the virtual path of the specified action.
Public method Static member RouteLink(HtmlHelper, String, String, String, String, String, RouteValueDictionary, IDictionary<String, Object>) Returns an anchor element (a element) that contains the virtual path of the specified action.
Top
Remarks

The LinkExtensions class contains methods that extend the HtmlHelper class. Each extension method renders an HTML anchor element (a element). The ActionLink method renders an element that links to an action method. The RouteLink method renders an element that links to a URL based on a route. The URL can resolve to an action method, a file, a folder, or some other resource.

Examples

The following example shows how to create HTML links using the ActionLink and RouteLink methods. The view contains a link to an action method and a link to a text file. The link to the text file uses a named route that is defined in the Global.asax file.

Visual Basic

<h2><%= Html.Encode(ViewData("Message")) %></h2>

<p><%=Html.ActionLink("Link to an action method", "LinkToAction")%></p>

<p><%=Html.RouteLink("Link to a text file", "TextFile", Nothing)%></p>


C#

<h2><%= Html.Encode(ViewData["Message"]) %></h2>

<p><%= Html.ActionLink("Link to an action method", "LinkToAction") %></p>

<p><%= Html.RouteLink("Link to a text file", "TextFile", null) %></p>


The following example shows the route definition that was added to the RegisterRoutes subroutine in the Global.asax file.

Visual Basic

routes.MapRoute( _
    "TextFile", _
    "{folder}/{file}.txt", _
    New With {.folder = "Content", .file = "Target"} _
)


C#

routes.MapRoute(
    "TextFile",                                  // Route name
    "{folder}/{file}.txt",                       // URL with parameters
    new { folder = "Content", file = "Target" }  // Parameter defaults
);


Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also

Reference

Other Resources

Community Content

3dmashup
Are the Examples valid for MVC 3 and Razor?
Are these examples valid for  ASP.NET MVC3 and Razor templates? $0What techniques can you use to   debug this stuff when its a mix of HTML and C#?$0 $0$0 $0 $0