I am writing my first MVC 3 aplication (in ASP.NET) and I don't know how I can(should) display the menu for different users.
My app is created as MVC3 Web Application and the menu look like this:
<div id="menucontainer">
<ul id="menu">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("Info", "Info", "Home")</li>
</ul>
</div>
I created two types of roles: user and admin. Now, I want to show another links for user(Projects, Profile) and for admin(Manage Projects, Manage Accounts, Manage news).
How I should do that?
I found solution:
<div id="menucontainer">
<ul id="menu">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("Info", "Info", "Home")</li>
@if ( Request.IsAuthenticated && HttpContext.Current.User.IsInRole
( "user" ) ) {
<li>Projects link</li>
<li>Profile link</li>
}
@if ( Request.IsAuthenticated && HttpContext.Current.User.IsInRole
( "admin" ) ) {
<li>Manage Projects link</li>
<li>Manage Accounts link</li>
}
</ul>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With