zoukankan      html  css  js  c++  java
  • mvc布局动态显示菜单

    在mvc布局页中显示动态菜单

    在我的数据库表中有menuid和parentid,我想从中显示嵌套菜单。 如果有人有解决方案,请帮助我,如果有任何其他的方法,这给了一个例子。 这是我的数据库
    Database Table Structure

    public ActionResult Index()
        {
            using (MachineShopDBEntities db = new MachineShopDBEntities())
            {
                List<MenuMaster> list = db.MenuMasters.ToList();
                ViewBag.MenuList = new SelectList(list);
            }
            return View();
        }
    

    这是我的模型

    public partial class MenuMaster
    {
        public int MenuID { get; set; }
        public string MenuText { get; set; }
        public string Description { get; set; }
        public Nullable<int> ParentID { get; set; }
        public string ControllerName { get; set; }
        public string ActionName { get; set; }
    
        public bool IsChecked { get; set; }
        public List<MenuMaster> menus { get; set; }
        public IEnumerable<SelectListItem> users { get; set; }
    }
    

    这是我的观点

    <ul class="sidebar-menu">
                    @{
                        if (ViewBag.MenuList != null)
                        {
                            foreach (var items in ViewBag.MenuList.Items)
                            {
                                string action = items.ActionName;
                                string controller = items.ControllerName;
                                <li class="treeview">
                                    @if (items.ParentID == items.MenuID)
                                    {
                                        <ul class="treeview-menu">
                                            <li class="treeview">
                                                <a href="/@items.ControllerName/@items.ActionName">
                                                    <i class="fa fa-angle-double-right"></i> <span>@items.MenuText</span>
                                                    <i class="fa fa-angle-left pull-right"></i>
                                                </a>
                                            </li>
                                        </ul>
                                    }
    
                                    <a href="/@items.ControllerName/@items.ActionName">
                                        <i class="fa fa-user"></i> <span>@items.MenuText</span>
                                        <i class="fa fa-angle-left pull-right"></i>
                                    </a>
                                </li>
    
                            }
                        }
                    }

    转载自:http://ask.sov5.cn/q/Mr2YRmjo1Q

    本文来自博客园,作者:.net&new,转载请注明原文链接:https://www.cnblogs.com/wugh8726254/p/15192300.html

  • 相关阅读:
    RobotFramework+Selenium2+Appium环境搭建
    spring mvc 依赖包
    linux
    清理linux 某个文件夹下面所有的log文件
    selenium grid2 使用远程机器的浏览器
    IntelliJ Idea 快捷键
    aop注解 自定义切面的注解写法
    springmvc多视图配置
    @Autowired(required = false)
    pom.xml配置详解
  • 原文地址:https://www.cnblogs.com/wugh8726254/p/15192300.html
Copyright © 2011-2022 走看看