Timsen
Timsen

Reputation: 4126

MVC 3 Hide actionlink

I need to hide a actionlink on my _layout view. if it have to be hidden or not depends on data from DB where it is said if the person is admin or not.

How to hide the action link?

I want to send a simple request to my controller asking if the person who is logged in is admin or not?

I do not want to use IsAuthenticated option

Upvotes: 0

Views: 1579

Answers (3)

Sam-k
Sam-k

Reputation: 1

if (User.IsInRole("Admin")) 
{ 
    <li>@Html.ActionLink("Admin", "Admin", "Admin") </li>
}

Upvotes: 0

Mark Good
Mark Good

Reputation: 4303

You may also be able to do something like this:

@if (Page.User.IsInRole("admin"))
{
   <li>@Html.ActionLink("Admin", "Admin", "Admin") </li>
}

Upvotes: 2

Timsen
Timsen

Reputation: 4126

Answer was simple

                      @if (Convert.ToBoolean(ViewData["admin"])==true)
                      {

                           <li>@Html.ActionLink("Admin", "Admin", "Admin") </li>

}

Upvotes: 4

Related Questions