Adding htmlattributes to a ActionLink

To add htmlattributes to a ActionLink might be needed for instance for the layout of the page.

@Html.ActionLink("Link text", "action", "Controller", null, new {style="float:left"})
//Adding a css class (need the @sign as class is a keyword for the compiler). It is also possible to use a Capitol C in Class but then it fails some validations.
@Html.ActionLink("Link text", "action", "Controller", null, new {@class="myCssClassName"})
 
//the syntax for the Html.ActionLink (used in this example is)
public static MvcHtmlString ActionLink(
	string linkText,
	string actionName,
	string controllerName,
	RouteValueDictionary routeValues,
	IDictionary<string, Object> htmlAttributes
)

Specifying what area an ActionLink should use

Using routevalues you can tell the html helper what area you want to create a action link to.

//create a link that will go to AreaName
Html.ActionLink("Link Text", "ActionName", "ControllerName", new { Area = "AreaName" }, new{})
//Default area (= no area)
Html.ActionLink("Link Text", "ActionName", "ControllerName", new { Area = "" }, new{})
 
//create a link that will go to AreaName and with some htmlAttributes
Html.ActionLink("Link Text", "ActionName", "ControllerName", new { Area = "AreaName" }, new{@class="myCssClass"})
 
 
//Definition
public static MvcHtmlString ActionLink(
	string linkText,
	string actionName,
	string controllerName,
	RouteValueDictionary routeValues,
	IDictionary<string, Object> htmlAttributes
)