如何在ASP,Net MVC3 Razor中动态加载数据库中的菜单和子菜单 [英] How to Dynamically load Menus and Submenus from Database in ASP,Net MVC3 Razor
问题描述
我想问一下ASP.Net MVC3 razor中的动态数据库驱动菜单加载。
这是我的
1.查看代码
2.菜单模型
3.菜单项目模型
4。导航模型结构
在这个项目中,我有不同的用户登录。对于每次登录,他们都受模块的限制。所以当用户用他们的登录进入应用程序时,他们只有有限的访问权限。用户A只能访问帐户和回复,用户B只能访问这样的报告。
实现这些事情我从数据库加载菜单
I want to ask about Dynamic Database Driven Menu Loading in ASP.Net MVC3 razor .
This is my
1.View Code
2.Model for Menu
3.Model For Menu Items
4.Navigation Model Structure
In this project i have different User Logins .For each login they are limited by modules .So When a user enter into the app with their login ,they have only a limited access to their account.ie,User A can access only Accounts and Reprts,User B can access only Reports Like that.
To implement these things am loading menu from Database
@{
ViewBag.Title = "Elixir ERP V1.0 Beta";
Layout = "~/Views/Shared/_LayoutUser.cshtml";
}
<div class="main-container">
<div class="main-wrapper">
<div class="scroll-top">
<a href="#" class="tip-top" title="Go Top"></a>
</div>
<div class="left-bar merge-left">
<!-- SEARCH BAR -->
<!-- LEFT NAV -->
@section leftnav{
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Elixir.Models
{
public class Menu
{
public Menu()
{
MenuItems = new List<MenuItem>();
}
public int Id { get; set; }
public string Name { get; set; }
public List<MenuItem> MenuItems { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Elixir.Models
{
public class MenuItem
{
public int Id { get; set; }
public int UserName { get; set; }
public string Name { get; set; }
public string ActionName { get; set; }
public string ControllerName { get; set; }
public string Url { get; set; }
public Menu ParentMenu { get; set; }
}
}
<ul class="side-navigation accordion" id="nav-accordion">
<li><a href="#">Home</a></li>
<li><a href="#">User Management</a>
<ul>
<li><a href="#">Create New User</a></li>
<li><a href="#">Manage Users</a></li>
<li><a href="#">View Users</a></li>
</ul>
</li>
<li><a href="#">Employee Management</a>
<ul>
<li><a href="#">Employee Registration</a></li>
<li><a href="#">Manage Employees</a></li>
<li><a href="#">View Employees</a></li>
</ul>
</li>
<li><a href="#">DMIT Management</a>
<ul>
<li><a href="#">Scan Management</a></li>
<li><a href="#">Report Generation</a></li>
</ul>
</li>
<li><a href="#">Franchise Management </a>
<ul>
<li><a href="#">Franchise Registration</a></li>
<li><a href="#">Franchise Fee Management</a></li>
<li><a href="#">Franchise Account Management</a></li>
</ul>
</li>
<li><a href="#">Customer Management </a>
<ul>
<li><a href="#">Customer Registration</a></li>
<li><a href="#">Manage Customer</a></li>
</ul>
</li>
<li><a href="#">Counseling Management</a>
<ul>
<li><a href="#">Add Counseling Session</a></li>
<li><a href="#">Manage Counseling Sessions</a></li>
</ul>
</li>
<li><a href="#">Accounts</a>
<ul>
<li><a href="#">Manage Income</a></li>
<li><a href="#">Manage Expense</a></li>
</ul>
</li>
<li><a href="#">Reports</a>
<ul>
<li><a href="#">Elxir Monthly Reports</a></li>
<li><a href="#">Elixir Yearly Reports</a></li>
<li><a href="#">Franchise Monthly Reports</a></li>
<li><a href="#">Franchise yearly Reports</a></li>
</ul>
</li>
</ul>
推荐答案
参考这些
http://www.iwantmymvc.com/render-dynamic-html-menu-with-razor-in-mvc-3 [ ^ ]
http://techbrij.com/role-based-menu-asp-net-mvc [<一个href =http://techbrij.com/role-based-menu-asp-net-mvctarget =_ blanktitle =新窗口> ^ ]
< a href =http://vizagtechie.blogspot.in/2012/06/dynamic-multi-level-jquery-menu-for.html> http://vizagtechie.blogspot.in/2012/06/dynamic-multi -level-jquery-menu-for.html [ ^ ]
Refer these
http://www.iwantmymvc.com/render-dynamic-html-menu-with-razor-in-mvc-3[^]
http://techbrij.com/role-based-menu-asp-net-mvc[^]
http://vizagtechie.blogspot.in/2012/06/dynamic-multi-level-jquery-menu-for.html[^]
这篇关于如何在ASP,Net MVC3 Razor中动态加载数据库中的菜单和子菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!