I am not aware of such a helper method in ASP.NET MVC, but it is pretty easy to collapse:
public static class HtmlExtensions { public static string ActionLinkUnlessCurrent(this HtmlHelper htmlHelper, string linkText, string actionName) { string currentAction = htmlHelper.ViewContext.RouteData.Values["action"].ToString(); if (actionName != currentAction) { return htmlHelper.ActionLink(linkText, actionName); } return linkText; } }
And then use it like this:
<%= Html.ActionLinkUnlessCurrent("Link Text", "Index") %>
Darin Dimitrov
source share