Reputation: 165
I need to hide a link if a user is not logged in, and show the link if the user is logged in. I should use HTML. But the following:
@if(Authorize(Roles = "admin")) <li>@Html.ActionLink(@Resources.LayoutLang.myarticles, "MyReviews", "Review")</li>
does not work. How to check the role in HTML?
Upvotes: 1
Views: 175
Reputation: 4000
If you just want to check that the user is signed in:
@if (Request.IsAuthenticated)
{
// do stuff
}
Upvotes: 1
Reputation: 10824
You can use IsInRole
@if (User.IsInRole("admin"))
{
<li>@Html.ActionLink(@Resources.LayoutLang.myarticles, "MyReviews", "Review")</li>
}
else
{
<li>Not logged in</li>
}
Upvotes: 0