In order to achieve this, the navigation menu becomes this style by using the MVC programming implementation of the slice, which is the URL of the controller that gets the method in the OnActionExecuting method of Supportfilterattribute This class every click of a menu Go to the database query click on the navigation menu
Save to the navigation menu click on the table information, according to this change the navigation menu click on the style;
Supportfilterattribute Code:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.Http.Filters;
Using SYSTEM.WEB.MVC;
Using System.Web.Routing;
Using Microsoft.Practices.Unity;
Using Sqlserver.entity;
Using SQLSERVER.BLL;
Using Sqlserver.dal;
Using Sqlserver.idal;
Namespace ManagerSystem.UI.Filters
{
public class SupportFilterAttribute:System.Web.Mvc.ActionFilterAttribute
{
public string ActionName {get; set;}
private string area;
public override void OnActionExecuted (ActionExecutedContext filtercontext)
{
Base. OnActionExecuted (Filtercontext);
}
<summary>
Action Plus [Supportfilter] executes the following code before executing actin, specifying parameters by [Supportfilter (actionname= "Index")]
</summary>
<param name= "Filtercontext" > page passed over the context </param>
public override void OnActionExecuting (ActionExecutingContext filtercontext)
{
Controller,action,id in the context of the read request
var routes = new RouteCollection ();
Routeconfig.registerroutes (routes);
Routedata Routedata = routes. Getroutedata (Filtercontext.httpcontext);
Remove the controller of the area Action,id
String ctlname = FilterContext.Controller.ToString ();
string[] Routeinfo = Ctlname.split ('. ');
string controller = NULL;
string action = null;
string id = null;
int iareas = Array.indexof (Routeinfo, "areas");
if (Iareas > 0)
{
Access area and controller
Area = Routeinfo[iareas + 1];
}
int ctlindex = Array.indexof (Routeinfo, "Controllers");
ctlindex++;
Controller = Routeinfo[ctlindex]. Replace ("Controller", "");
String url = HttpContext.Current.Request.Url.ToString ();
string[] Urlarray = URL. Split ('/');
int urlctlindex = Array.indexof (Urlarray, Controller);
urlctlindex++;
if (Urlarray.count () > Urlctlindex)
{
action = Urlarray[urlctlindex];
}
urlctlindex++;
if (Urlarray.count () > Urlctlindex)
{
id = urlarray[urlctlindex];
}
//url
Action = string. IsNullOrEmpty (action)? "Index": action;
int actionindex = action. IndexOf ("?", 0);
if (Actionindex > 1)
{
action = action. Substring (0, Actionindex);
}
id = string. IsNullOrEmpty (ID)? "": ID;
URL path
string filePath = HttpContext.Current.Request.FilePath;
Changemenu (".." + FilePath);
}
public void Changemenu (string url)
{
using (Navbar_menubll nav = new NAVBAR_MENUBLL ()
{
menu = new Navbar_menuservice ()
})
{
if (!string. IsNullOrEmpty (URL))
{
Navbar_menu me = nav. Selectmenubyurl (URL);
if (me = null)
{
if (Me. parent_menu_id = = 1)
{
Menu_operation oper = new menu_operation ();
Oper. menu_id = Me. Nav_menuid;
Using (MENU_OPERATIONBLL op = new MENU_OPERATIONBLL ()
{
Operation = new Menu_operationservice ()
})
{
Op. Addmenu_operation (oper);
}
}
Else
{
Navbar_menu m = nav. Selectmenubyid (Me. PARENT_MENU_ID);
if (!string. IsNullOrEmpty (M.menu_url))
{
Changemenu (M.menu_url);
}
Else
{
Selectnav (M.NAV_MENUID);
}
}
}
}
}
}
public void Selectnav (int pid)
{
using (NAVBAR_MENUBLL nav1 = new NAVBAR_MENUBLL ()
{
menu = new Navbar_menuservice ()
})
{
Navbar_menu m = nav1. Selectmenubyid (PID);
if (m.parent_menu_id = = 1)
{
Menu_operation oper = new menu_operation ();
Oper. menu_id = M.nav_menuid;
Using (MENU_OPERATIONBLL op = new MENU_OPERATIONBLL ()
{
Operation = new Menu_operationservice ()
})
{
Op. Addmenu_operation (oper);
}
}
Else
{
Selectnav (m.parent_menu_id);
}
}
}
public override void Onresultexecuted (ResultExecutedContext filtercontext)
{
Base. Onresultexecuted (Filtercontext);
}
public override void Onresultexecuting (ResultExecutingContext filtercontext)
{
Base. Onresultexecuting (Filtercontext);
}
}
}
Changing the menu style code
$.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 (2)