Пример #1
0
        private BreadCrumbNavModel InitBreadCrumb(ResultExecutingContext filterContext)
        {
            var area       = filterContext.RouteData.DataTokens.ContainsKey("area") ? filterContext.RouteData.DataTokens["area"].ToString().ToLower() : string.Empty;
            var controller = filterContext.RouteData.Values["controller"].ToString().ToLower();
            var action     = filterContext.RouteData.Values["action"].ToString().ToLower();

            string linkUrl = string.Format("{0}/{1}/{2}", area, controller, action);

            var model = new BreadCrumbNavModel();

            var indexModel = new BreadCrumbModel
            {
                Name     = "首页",
                Icon     = "icon-home",
                IsParent = false,
                IsIndex  = true
            };

            if (area == "common" && controller == "home" && action == "index")
            {
                model.CurrentName = "首页";
            }

            model.BreadCrumbList.Add(indexModel);

            var module = ModuleService.Modules.Where(t => t.LinkUrl.ToLower().Contains(linkUrl) && t.IsDeleted == false && t.Enabled == true).FirstOrDefault();

            if (module != null)
            {
                //有父菜单
                if (module.ParentId != null)
                {
                    var pmModule = ModuleService.Modules.Where(t => t._ID == module.ParentId).FirstOrDefault();
                    if (pmModule != null)
                    {
                        var parentModel = new BreadCrumbModel
                        {
                            IsParent = true,
                            Name     = pmModule.Name,
                            Icon     = pmModule.Icon,
                            LinkUrl  = pmModule.LinkUrl
                        };
                        model.BreadCrumbList.Add(parentModel);
                    }
                }

                var currentModel = new BreadCrumbModel
                {
                    IsParent = false,
                    Name     = module.Name,
                    Icon     = ""
                };

                model.CurrentName = currentModel.Name;
                model.BreadCrumbList.Add(currentModel);

                ((ViewResult)filterContext.Result).ViewBag.CurrentTitle = module.Name;
            }
            return(model);
        }
Пример #2
0
        private BreadCrumbNavModel InitBreadCrumb(ResultExecutingContext filterContext)
        {
            var area       = filterContext.RouteData.DataTokens.ContainsKey("area") ? filterContext.RouteData.DataTokens["area"].ToString().ToLower() : string.Empty;
            var controller = filterContext.RouteData.Values["controller"].ToString().ToLower();
            var action     = filterContext.RouteData.Values["action"].ToString().ToLower();

            string linkUrl = string.Format("{0}/{1}/{2}", area, controller, action);

            var model = new BreadCrumbNavModel();

            var indexModel = new BreadCrumbModel
            {
                Name     = "Home",
                Icon     = "icon-home",
                IsParent = false,
                IsIndex  = true
            };

            if (area == "common" && controller == "home" && action == "index")
            {
                model.CurrentName = "Home";
            }

            model.BreadCrumbList.Add(indexModel);

            //Ben 2016-12-27
            SortedList <string, BreadCrumbModelArray <BreadCrumbModel> > ls = InitBreadCrumbArray();

            if (ls.ContainsKey(area))
            {
                if (ls[area] != null)
                {
                    var parentModel = new BreadCrumbModel
                    {
                        IsParent = true,
                        Name     = ls[area].Name,
                        Icon     = ls[area].Icon
                    };
                    model.BreadCrumbList.Add(parentModel);

                    var currentModel = ls[area].getItem(controller);
                    if (currentModel != null)
                    {
                        model.BreadCrumbList.Add(currentModel);
                    }
                }
            }

            /*
             * var module = ModuleService.Modules.FirstOrDefault(t => t.LinkUrl.ToLower().Contains(linkUrl) && t.IsDeleted == false && t.Enabled == true);
             *
             * if (module != null)
             * {
             *  //有父菜单
             *  if (module.ParentModule != null)
             *  {
             *      var parentModel = new BreadCrumbModel
             *      {
             *          IsParent = true,
             *          Name = module.ParentModule.Name,
             *          Icon = module.ParentModule.Icon
             *      };
             *      model.BreadCrumbList.Add(parentModel);
             *  }
             *
             *  var currentModel = new BreadCrumbModel
             *  {
             *      IsParent = false,
             *      Name = module.Name,
             *      Icon = ""
             *  };
             *
             *  model.CurrentName = currentModel.Name;
             *  model.BreadCrumbList.Add(currentModel);
             *
             *  ((ViewResult)filterContext.Result).ViewBag.CurrentTitle = module.Name;
             * }
             */
            return(model);
        }