Mvc+ajax Rights Management

Source: Internet
Author: User

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

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.