Mvc+bootstrap Enterprise General framework Construction--implementation of the left navigation menu (1)

Source: Internet
Author: User

Implementation of the navigation menu: Navbar_menu

public class Navbar_menu
{
<summary>
Navigation Menu Number
</summary>
private int _nav_menuid;

public int Nav_menuid
{
get {return _nav_menuid;}
set {_nav_menuid = value;}
}
<summary>
Menu Name
</summary>
private string _menu_name;

public string Menu_name
{
get {return _menu_name;}
set {_menu_name = value;}
}
<summary>
Menu URL
</summary>
private string _menu_url;

public string Menu_url
{
get {return _menu_url;}
set {_menu_url = value;}
}
<summary>
Parent Menu ID
</summary>
private int _parent_menu_id;

public int parent_menu_id
{
get {return _parent_menu_id;}
set {_parent_menu_id = value;}
}
<summary>
Menu icon
</summary>
private string _menu_ico;

public string Menu_ico
{
get {return _menu_ico;}
set {_menu_ico = value;}
}
<summary>
Menu Flags
</summary>
private string _menu_ico_tag;

public string Menu_ico_tag
{
get {return _menu_ico_tag;}
set {_menu_ico_tag = value;}
}
<summary>
Whether there is a subset menu
</summary>
private bool _isexit_children_menu;

public bool Isexit_children_menu
{
get {return _isexit_children_menu;}
set {_isexit_children_menu = value;}
}
<summary>
Creation time
</summary>
Private DateTime _cratetime_menu;

Public DateTime Cratetime_menu
{
get {return _cratetime_menu;}
set {_cratetime_menu = value;}
}
<summary>
Menu Subset
</summary>
Private list<navbar_menu> _children_menu;

Public list<navbar_menu> Children_menu
{
get {return _children_menu;}
set {_children_menu = value;}
}
<summary>
Menu sort
</summary>
private int _menu_num;

public int Menu_num
{
get {return _menu_num;}
set {_menu_num = value;}
}
<summary>
Menu Description
</summary>
private string _menu_detail_explain;

public string Menu_detail_explain
{
get {return _menu_detail_explain;}
set {_menu_detail_explain = value;}
}
<summary>
Menu status (Show/Hide)
</summary>
private bool _menu_staus;

public bool Menu_staus
{
get {return _menu_staus;}
set {_menu_staus = value;}
}
<summary>
Menu level
</summary>
private int _level;

public int Level
{
get {return _level;}
set {_level = value;}
}
<summary>
Whether to expand
</summary>
private bool? _is_foldingup;

public bool? Is_foldingup
{
get {return _is_foldingup;}
set {_is_foldingup = value;}
}
}

Implementation of the idea: the Main method of recursion, according to the ID query itself node, in accordance with its own parent ID to query the Father node information, if there is a sub-click has been recursive; code is a concatenation of the string to the UL Li into a string to form the left side of the accordion menu;

Asynchronously called on the main page, appends the string formation, in order to improve performance using the cache;

Code:

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using SYSTEM.WEB.MVC;
Using Managersystem.utility;
Using Microsoft.Practices.Unity;
Using SQLSERVER.IBLL;
Using Managersystem.di;
Using Sqlserver.entity;
Using ManagerSystem.UI.Filters;
Namespace ManagerSystem.UI.Controllers
{

public class Sharedcontroller:basecontroller
{
Public ActionResult Main ()
{
return View ();
}
[Dependency]
Public INAVBAR_MENUBLL menu {get; set;}
[Dependency]
Public IMENU_OPERATIONBLL operation {get; set;}
String sysrem_navbar_menues = "";

Get all the navigation menus recursively
[Acceptverbs (Httpverbs.post)]
Public Jsonresult Getallnavbarmenu (string navname)
{
if (Cachehelper.getcache ("sysrem_navbar_menues") = null)
{
Sysrem_navbar_menues = Cachehelper.getcache ("Sysrem_navbar_menues"). ToString ();
}
Else
{
Sysrem_navbar_menues + = "<ul class=\" page-sidebar-menu\ "data-auto-scroll=\" true\ "data-slide-speed=\" 200\ ">" ;
Sysrem_navbar_menues + = "<li class=\" Sidebar-toggler-wrapper\ ">";
Sysrem_navbar_menues + = "<div class=\" Sidebar-toggler hidden-phone\ ">

Sysrem_navbar_menues + = "<li class=\" sidebar-search-wrapper\ "><form class=\" sidebar-search\ "action=\" \ " Method=\ "post\" > ";
Sysrem_navbar_menues + = "<div class=\" form-container\ "><div class=\" input-box\ "><a href=\" javascript :; \ "Class=\" remove\ "></a><input type=\" text\ "placeholder=\" search...\ "/><input type=\" button\ " Class=\ "submit\" value=\ "\"/> </div></div></form></li> ";
Sysrem_navbar_menues + = menu_string (1, navname);
Sysrem_navbar_menues + = "</ul>";
Cachehelper.setcache ("Sysrem_navbar_menues", sysrem_navbar_menues);
}

Return Json (sysrem_navbar_menues);
}
public string menu_string (int mid,string title)
{
String message_menu = "";
Message_menu + = "";

List<navbar_menu> nav = Menu. Selectchildrenmenubyid (mid);

for (int i = 0; I < NAV. Count; i++)
{
if (!string. IsNullOrEmpty (Nav[i]. Menu_detail_explain))
{
Message_menu + = "<li id=" + "\" "+nav[i]. Nav_menuid+ "\" + "name=" + "\" "+nav[i". Parent_menu_id+ "\" "+" class=\ "tooltips\" ";
Message_menu + = "data-container=\" body\ "data-placement=\" right\ "data-html=\" true\ "data-original-title=\" "+ nav[i" . Menu_detail_explain + "\" "+" > ";
}
Else
{
Message_menu + = "<li id=" + "\" "+ nav[i]. Nav_menuid + "\" + "name=" + "\" "+ nav[i]. parent_menu_id + "\" "+" > ";
}
if (Nav[i]. parent_menu_id = = 1)
{
Message_menu + = "<a onclick=\" Changestyle (this) \ "";
}
Else
{
Message_menu + = "<a onclick=\" Changelistyle (this) \ "";
}
Message_menu + = "href=" + "\" "+ (String. IsNullOrEmpty (Nav[i]. Menu_url) = = true? "javascript:;": Nav[i]. Menu_url) + "\" "+" ><i class=\ "FA" + nav[i]. Menu_ico + "\" "+" > "+" </i><span class=\ "title\" > "+ nav[i". Menu_name + "</span>";
if (!string. IsNullOrEmpty (Nav[i]. Menu_ico_tag))
{
Message_menu + = "<span class=\" badge badge-roundless badge-success\ ">" + nav[i]. Menu_ico_tag + "</span>";
}
if (Nav[i]. Isexit_children_menu)
{
Message_menu + = "<span class=\" arrow \ "></span></a>";
List<navbar_menu> nav2 = Menu. Selectchildrenmenubyid (Nav[i]. NAV_MENUID);
Message_menu + = "<ul class=\" sub-menu\ ">";
foreach (Var m1 in Nav2)
{

if (M1. Isexit_children_menu)
{
Navbar_menu me = Menu. Selectmenubyid (M1. NAV_MENUID);
Message_menu + = "<li id=" + "\" "+ nav[i]. Nav_menuid + "\" + "name=" + "\" "+ nav[i]. parent_menu_id + "\" "+" ><a href= "+" \ "" + (String. IsNullOrEmpty (Me. Menu_url) = = true? "javascript:;": me. Menu_url) + "\" "+" ><i class=\ "fa" + me. Menu_ico + "\" "+" > "+" </i><span class=\ "title\" > "+ Me. Menu_name + "</span>";
Message_menu + = "<span class=\" arrow \ "></span></a>";
Message_menu + = "<ul class=\" sub-menu\ ">";
Message_menu + = Menu_string (M1. Nav_menuid, "");
Message_menu + = "</ul>";
Message_menu + = "</li>";
}
Else
{
if (!string. IsNullOrEmpty (M1. Menu_detail_explain))
{
Message_menu + = "<li id=" + "\" "+ nav[i]. Nav_menuid + "\" + "name=" + "\" "+ nav[i]. parent_menu_id + "\" "+" class=\ "tooltips\" data-container=\ "body\" data-placement=\ "right\" data-html=\ "true\" Data-original-title=\ "" + M1. Menu_detail_explain + "\" "+" > ";
}
Else
{
Message_menu + = "<li id=" + "\" "+ nav[i]. Nav_menuid + "\" + "name=" + "\" "+ nav[i]. parent_menu_id + "\" "+" > ";
}
Message_menu + = "<a onclick=\" Changelistyle (this) \ "href=" + "\" "+ (String. IsNullOrEmpty (M1. Menu_url) = = true? "javascript:;": M1. Menu_url) + "\" "+" ><i class=\ "FA" + M1. Menu_ico + "\" + ">" + "</i><span class=\" title\ ">" + M1. Menu_name + "</span>";
if (!string. IsNullOrEmpty (M1. Menu_ico_tag))
{
Message_menu + = "<span class=\" badge badge-roundless badge-success\ ">" + M1. Menu_ico_tag + "</span>";
}
Message_menu + = "</a></li>";
}

}
Message_menu + = "</ul>";
}
Else
{
if (!string. IsNullOrEmpty (Nav[i]. Menu_ico_tag))
{
Message_menu + = "<span class=\" badge badge-roundless badge-success\ ">" + nav[i]. Menu_ico_tag + "</span>";
}
}
Message_menu + = "</a></li>";

}
return message_menu;
}


public void Diesystem ()
{
session["user_name"] = null;
session["sysrem_navbar_menues"] = null;
if (request.cookies["Cookie_name_for_user"]! = NULL)
{
HttpCookie cookies = new HttpCookie ("Cookie_name_for_user");
Cookies. Expires = DateTime.Now.AddDays (-1);
RESPONSE.COOKIES.ADD (Cookies);
}
}

public void Addmenu_operation (string menu_id)
{
Menu_operation m = new menu_operation ();
m.menu_id = Convert.ToInt32 (menu_id);
Operation. Addmenu_operation (m);
}
[Acceptverbs (Httpverbs.post)]
Public Jsonresult getmenu_operation ()
{
Menu_operation m = operation. Getnewmenuoperation ();
Return Json (M, jsonrequestbehavior.denyget);
}
}
}

Ajax code that is called on the main page

$.ajax ({
Type: "POST",
URL: "). /shared/getallnavbarmenu? "+ math.random (). toString (),
Data:{navname:" "},
Success:function (msg) {
$ (" # Nav_menu "). empty ();
$ ("#nav_menu"). Append (msg);
$.ajax ({
Type: "POST",
URL: "). /shared/getmenu_operation? "+ math.random (). toString (),
Success:function (msg) {
if (msg). menu_id = = "" | Msg. menu_id = = NULL | Msg. menu_id = = undefined) {
$ ("#nav_menu >ul>li"). EQ (2). Removeclass ("active"). AddClass ("active");
}
$ ("#nav_menu >ul>li>a"). Append ("<span class=\" selected\ "></span>");
$ ("#nav_menu >ul>li"). Removeclass ("active open");
$ ("#" + Msg.) menu_id). Removeclass ("active Open"). AddClass ("active open");
$ ("#" + Msg.) menu_id). Children ("ul"). CSS ("Display", "block");
}
});
App.init ();
}
});

function Changestyle (obj) {
$ ("#nav_menu >ul>li"). Removeclass ("active");
var title = $ (obj). Parent (). attr ("id");
$ (obj). Parent (). Removeclass ("active"). AddClass ("active");
}
function Changelistyle (obj) {
$.ajax ({
Type: "POST",
URL: ".. /shared/addmenu_operation? "+ math.random (). toString (),
data:{menu_id:$ (obj). Parent (). attr ("id")},
Success:function (msg) {
}
});
}

Mvc+bootstrap Enterprise General framework Construction--implementation of the left navigation menu (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.