title: Building an ASP.NET MVC Master Page Menu Dynamically, Based on the current User's "Role"
body: <p>I've seen some similar questions, but none that look like what I'm trying to do.</p>
  
  <p>This is my current implementation w/out any security:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;div id="menucontainer"&gt;
      &lt;ul id="menu"&gt;              
          &lt;li&gt;&lt;%= Html.ActionLink("Main List", "Index", "AController")%&gt;&lt;/li&gt;
          &lt;li&gt;&lt;%= Html.ActionLink("Product List", "Index", "BController")%&gt;&lt;/li&gt;
          &lt;li&gt;&lt;%= Html.ActionLink("Company List", "Index", "CController")%&gt;&lt;/li&gt;
          &lt;li&gt;&lt;%= Html.ActionLink("User List", "Index", "DController")%&gt;&lt;/li&gt;
      &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This is fine, and the above works. I have [Authorize] Attributes setup on the Actions for CController and DController to prevent unauthorized access -- but I'd like to remove those items from the menu for users who don't have the correct Role, because when they see it and click on it and it tells them they don't have permission, they'll want it. If they don't know it's there, that's just better for everyone involved...</p>
  
  <p>Something like this is ultimately the goal I'm trying to get at, but I'm looking for the more MVC Flavored aproach, where the "view" is "dumb":</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;div id="menucontainer"&gt;
      &lt;ul id="menu"&gt;              
          &lt;li&gt;&lt;%= Html.ActionLink("Main List", "Index", "AController")%&gt;&lt;/li&gt;
          &lt;li&gt;&lt;%= Html.ActionLink("Product List", "Index", "BController")%&gt;&lt;/li&gt;
          &lt;% If(Role = Roles.Admin) { %&gt;
          &lt;li&gt;&lt;%= Html.ActionLink("Company List", "Index", "CController")%&gt;&lt;/li&gt;
          &lt;li&gt;&lt;%= Html.ActionLink("User List", "Index", "DController")%&gt;&lt;/li&gt;
          &lt;% } %&gt;
      &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>