You could write a helper:
public static class HtmlExtensions
{
public static IHtmlString MyActionLink(
this HtmlHelper htmlHelper,
string linkText,
string action,
string controller,
object routeValues,
object htmlAttributes
)
{
var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
var anchor = new TagBuilder("a");
anchor.InnerHtml = linkText;
anchor.Attributes["href"] = urlHelper.Action(action, controller, routeValues);
anchor.MergeAttributes(new RouteValueDictionary(htmlAttributes));
return MvcHtmlString.Create(anchor.ToString());
}
}
and then use this helper:
@Html.MyActionLink(
"<span>Hello World</span>",
"foo",
"home",
new { id = "123" },
new { @class = "foo" }
)
which given default routes would produce:
<a class="foo" href="/home/foo/123"><span>Hello World</span></a>