Guest User

Untitled

a guest
Nov 17th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. public static string IsSelected( this HtmlHelper html, string controller = null, string action = null, string area = null ) {
  2. string cssClass = "active";
  3. string currentAction = (string)html.ViewContext.RouteData.Values[ "action" ];
  4. string currentController = (string)html.ViewContext.RouteData.Values[ "controller" ];
  5. string currentArea = html.ViewContext.RouteData.DataTokens[ "area" ] == null ? String.Empty : (string)html.ViewContext.RouteData.DataTokens[ "area" ];
  6.  
  7. if ( String.IsNullOrEmpty( controller ) )
  8. controller = currentController;
  9.  
  10. if ( String.IsNullOrEmpty( action ) )
  11. action = currentAction;
  12.  
  13. if ( String.IsNullOrEmpty( area ) )
  14. area = currentArea;
  15.  
  16. if ( controller.ToLower() == currentController.ToLower() && action.ToLower() == currentAction.ToLower() && area == currentArea ) {
  17. return cssClass;
  18. }
  19. else {
  20. return string.Empty;
  21. }
  22. }
  23.  
  24. <li class="treeview @Html.IsSelected( controller: "mycontroller", action : string.Empty, area : string.Empty )">
  25. <a href="#">
  26. <i class="fa fa-list-alt"></i> <span>Menu 1</span>
  27. <span class="pull-right-container">
  28. <i class="fa fa-angle-right pull-right"></i>
  29. </span>
  30. </a>
  31. <ul class="treeview-menu">
  32. <li class="@Html.IsSelected( controller: "mycontroller", action : "myaction", area : string.Empty )">
  33. <a href="@Url.Action("myaction", "mycontroller" )">
  34. <i class="fa fa-retweet"></i>
  35. My Action &nbsp;
  36. </a>
  37. </li>
  38. </ul>
  39. </li>
Add Comment
Please, Sign In to add comment