예제 #1
0
        public static string IsSelected(this HtmlHelper html, string action = null, List <string> controllers = null, CssClass cssClass = CssClass.Select)
        {
            string _cssClass         = cssClass.GetDisplayName();
            string currentAction     = (string)html.ViewContext.RouteData.Values["action"];
            string currentController = (string)html.ViewContext.RouteData.Values["controller"];

            if (string.IsNullOrEmpty(action))
            {
                action = currentAction;
            }

            var re = controllers.Select(Controller => string.IsNullOrEmpty(Controller) ? currentController : Controller).Any(Controller => Controller.ToLower() == currentController.ToLower() && action.ToLower() == currentAction.ToLower());

            return(re ? _cssClass : string.Empty);
        }
예제 #2
0
        public static string IsSelected(this HtmlHelper html, string action = null, string controller = null, CssClass cssClass = CssClass.Select)
        {
            string _cssClass         = cssClass.GetDisplayName();
            string currentAction     = (string)html.ViewContext.RouteData.Values["action"];
            string currentController = (string)html.ViewContext.RouteData.Values["controller"];

            if (string.IsNullOrEmpty(controller))
            {
                controller = currentController;
            }

            if (string.IsNullOrEmpty(action))
            {
                action = currentAction;
            }

            return(controller == currentController && action == currentAction ? _cssClass : string.Empty);
        }