asp.net mvc - Turn menu options on/off from Masterpage depending on user privs -


i have been trying find way access master page control in order show/hide menu option.

in mp, have:

   <div id="menucontainer">         &nbsp;             <ul id="menu">                               <li id="menuhome"><%= html.actionlink("home", "index", "home")%></li>                 <li id="menunewhire"><%= html.actionlink("new hire", "index",     "newhire")%></li>                 <li><%= html.actionlink("software", "index", "software")%></li>                 <li><%= html.actionlink("hardware", "index", "hardware")%></li>                 <li><%= html.actionlink("telecom", "index", "telecom")%></li>                 <li><%= html.actionlink("about", "about", "home")%> </li> 


then contentplaceholder after that..what want in controller, see if user in ad group, if so, show or hide 1 of menu options. in case, mnunewhire want visible users.

any ideas on how this? in advance , help.

geo...

i externalize menu separate controller , use html.action helper method. example have model:

public class usermodel {     public bool isnoob { get; set; } } 

then controller:

public class menucontroller: controller {     private readonly iusersrepository _repository;     public menucontroller(iusersrepository repository)     {         _repository = repository;     }      public actionresult index()     {         var username = user.identity.name;         var usermodel = new usermodel         {             // maybe use membership provider here             // don't know how handling authorization             isnoob = _repository.getusergroup(username) == "noobs"         }         return view(usermodel);     } } 

and corresponding partial view:

<ul id="menu">                   <li id="menuhome"><%= html.actionlink("home", "index", "home")%></li>     <% if (model.isnoob) { %>         <li id="menunewhire"><%= html.actionlink("new hire", "index", "newhire")%></li>     <% } %>     <li><%= html.actionlink("software", "index", "software")%></li>     <li><%= html.actionlink("hardware", "index", "hardware")%></li>     <li><%= html.actionlink("telecom", "index", "telecom")%></li>     <li><%= html.actionlink("about", "about", "home")%> </li> </ul> 

and in master page:

<div id="menucontainer">     <%= html.action("index", "menu") %> </div> 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -