public T IfActiveItem <T>(string key, T thenTrueResult, T elseFalseResult = default(T))
        {
            var menuData = _htmlHelper.ViewContext.HttpContext.Items[nameof(MenuData)] as MenuData;

            if (menuData == null)
            {
                menuData = new MenuData();
            }

            var result = menuData.Items.Any(i => i.Like(key)) ? thenTrueResult : elseFalseResult;

            return(result);
        }
Example #2
0
        public T IfActiveItem <T>(string key, T thenTrueResult, T elseFalseResult = default(T))
        {
            var menuData = _htmlHelper.ViewContext.HttpContext.Items[nameof(MenuData)] as MenuData;

            if (menuData == null)
            {
                menuData = new MenuData();
            }

            var result = menuData.Items.Any(i => Regex.IsMatch(i, key, RegexOptions.IgnoreCase)) ? thenTrueResult : elseFalseResult;

            return(result);
        }
        public void TrackItem(string key)
        {
            var itemsKey = nameof(MenuData);

            var menuData = _controllerContext.HttpContext.Items[itemsKey] as MenuData;

            if (menuData == null)
            {
                menuData = new MenuData();
            }

            menuData.Items.Add(key);

            _controllerContext.HttpContext.Items[itemsKey] = menuData;
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var itemsKey = nameof(MenuData);

            var menuData = filterContext.HttpContext.Items[itemsKey] as MenuData;

            if (menuData == null)
            {
                menuData = new MenuData();
            }

            menuData.Items.AddRange(GetControllerItems(filterContext));
            menuData.Items.AddRange(GetActionItems(filterContext));

            filterContext.HttpContext.Items[itemsKey] = menuData;
        }