Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string IsSelected( this HtmlHelper html, string controller = null, string action = null, string area = null ) {
- string cssClass = "active";
- string currentAction = (string)html.ViewContext.RouteData.Values[ "action" ];
- string currentController = (string)html.ViewContext.RouteData.Values[ "controller" ];
- string currentArea = html.ViewContext.RouteData.DataTokens[ "area" ] == null ? String.Empty : (string)html.ViewContext.RouteData.DataTokens[ "area" ];
- if ( String.IsNullOrEmpty( controller ) )
- controller = currentController;
- if ( String.IsNullOrEmpty( action ) )
- action = currentAction;
- if ( String.IsNullOrEmpty( area ) )
- area = currentArea;
- if ( controller.ToLower() == currentController.ToLower() && action.ToLower() == currentAction.ToLower() && area == currentArea ) {
- return cssClass;
- }
- else {
- return string.Empty;
- }
- }
- <li class="treeview @Html.IsSelected( controller: "mycontroller", action : string.Empty, area : string.Empty )">
- <a href="#">
- <i class="fa fa-list-alt"></i> <span>Menu 1</span>
- <span class="pull-right-container">
- <i class="fa fa-angle-right pull-right"></i>
- </span>
- </a>
- <ul class="treeview-menu">
- <li class="@Html.IsSelected( controller: "mycontroller", action : "myaction", area : string.Empty )">
- <a href="@Url.Action("myaction", "mycontroller" )">
- <i class="fa fa-retweet"></i>
- My Action
- </a>
- </li>
- </ul>
- </li>
Add Comment
Please, Sign In to add comment