Do not like to say nonsense, directly when:
1. Controller
/// <summary> ///Get list/// </summary> /// <returns></returns> PublicActionResult getrolelist () {returnView (); } Public stringGETLISTF (intID) {List<CM_Menu> list=_menuservice.getlistf (ID); stringHTML =""; if(list. Count >0) { foreach(varIteminchlist) {HTML+="<li><button Onclick=getmenu ("+ Item. Id +") class= ' button ' >"+ Item. Name +"</button>"; } } returnhtml; } /// <summary> ///Sub-menu loading (permissions)/// </summary> /// <param name= "id" ></param> /// <returns></returns> Public stringGetlistson (intID) {//Authority judgmentCm_info_role Rolemodel = session["Inforole"] asCm_info_role; stringRole =Rolemodel.role; List<CM_Menu> list=_menuservice.getlistson (ID); stringHTML =""; if(list. Count >0) { for(inti =0; I < list. count;i++ ) { inttemp = Convert.ToInt32 (List[i]. Showname.replace ("role",""). Trim ()); if(role. Substring (temp,1) =="1") {HTML+="<li><a href= '"+ List[i]. URL +"' target= ' _blank ' >"+ List[i]. Name +"</a></li>"; } Else{html+=""; } } } returnhtml; }
2. Ajax
functionBodyonload ()//is loaded with the parent ID 0, which is the main menu{ vardata = 0; $.ajax ({type:' Post ', Async:false, data: {id:data}, URL:'/menu/getlistf ', DataType:' HTML ', Success:function(JSON, Textstatus) {$ ("#MenuListF"). Append (JSON); }, Complete:function(XMLHttpRequest, Textstatus) {}, Error:function(XMLHttpRequest, Textstatus, Errorthrown) {$.messager.alert ("Failure Prompt", Textstatus); } }); //getmenu (0);//Initialize load 0}functionGetMenu (FID)//Get{$.ajax ({type:' Post ', Async:false, data: {id:fid}, URL:'/menu/getlistson ', DataType:' HTML ', Success:function(JSON, textstatus) {//if (!$ ("#MenuListSon"). has ("Li"). Length) { //$ ("#MenuListSon"). Append (JSON); //} //else {$ ("#MenuListSon > *"). Remove (); $("#MenuListSon"). Append (JSON); //}}, Complete:function(XMLHttpRequest, Textstatus) {}, Error:function(XMLHttpRequest, Textstatus, Errorthrown) {$.messager.alert ("Failure Prompt", Textstatus); } });}
3. Page
<DivID= "Head_wrap"class= "Container_12"> <DivID= "logo"class= "Grid_4"> <H1><span>Logo</span></H1> </Div> <DivID= "ControlPanel"class= "Grid_8"> <ul> <Li><P><Strong>Hello, user name</Strong></P></Li> </ul> </Div> <DivID= "Navigation"class= "Grid_12"> <ulID= "MENULISTF"> </ul> </Div> </Div><!--End Headwarp -
In front of the great God, this is a dish, but when loading this menu, it may be because of the novice's sake, to solve their own problems are quite satisfactory.
Explain:
Inside the controller is actually the output HTML string, Ajax inside is to load this string. Page Call display
inttemp = Convert.ToInt32 (List[i]. Showname.replace ("role",""). Trim ()); if(role. Substring (temp,1) =="1") {HTML+="<li><a href= '"+ List[i]. URL +"' target= ' _blank ' >"+ List[i]. Name +"</a></li>"; } Else{html+=""; }
Here is actually my permission to judge, I think that the background code is not so easy to expose, because this permission is based on User, Menu, role do, I think this is the way this idea
Mvc+ajax Rights Management