Skip to content

Instantly share code, notes, and snippets.

@zihotki
Created September 14, 2012 22:21
Show Gist options
  • Select an option

  • Save zihotki/3725306 to your computer and use it in GitHub Desktop.

Select an option

Save zihotki/3725306 to your computer and use it in GitHub Desktop.
asp.net mvc MenuLink extension
public static MvcHtmlString MenuLink(
this HtmlHelper helper,
string text, string action, string controller)
{
var routeData = helper.ViewContext.RouteData.Values;
var currentController = routeData["controller"];
var currentAction = routeData["action"];
if(String.Equals(action, currentAction as string,
StringComparison.OrdinalIgnoreCase)
&&
String.Equals(controller, currentController as string,
StringComparison.OrdinalIgnoreCase))
{
return helper.ActionLink(
text,action, controller, null,
new { @class="currentMenuItem"}
);
}
return helper.ActionLink(text, action, controller);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment