开发者

ASP.NET MVC - menu for different roles

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">
           开发者_Go百科     <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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜