Reputation: 29
I have a default internet application template from MVC4 and I would like to add some links to the <nav>
tag depending on the user logged in.
I.e all the users have a default navigation panel, but if it is an admin logged in, he should have extra link for Managing product stock.
Right now it looks like that(from _Layout.cshtml):
<nav>
<ul id="menu">
<li>@Html.ActionLink("Home", "Browse", "Product")</li>
...
</ul>
</nav>
And I need somehow insert new ActionLink. I've tried to make an if
statement inside the default layout, but it does not work. How could I add an extra <li>
tag inside this <nav>
? I am not familiar with JavaScript or JQuery, but can it be done using MVC features?
Upvotes: 0
Views: 132
Reputation: 1288
Yes this can be achieved using the razor syntax
<nav>
<ul id="menu">
<li>@Html.ActionLink("Home", "Browse", "Product")</li>
@if( User.IsInRole("Admin") ){
<li>@Html.ActionLink("Admin", "...", "...")</li>
}
</ul>
</nav>
Upvotes: 1