开发者

MVC 3 Hide actionlink

开发者 https://www.devze.com 2023-04-01 01:58 出处:网络
I need to hide a actionlink on my _layout view. if it have to be hidden or not depends o开发者_高级运维n data from DB where it is said if the person is admin or not.

I need to hide a actionlink on my _layout view. if it have to be hidden or not depends o开发者_高级运维n 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


Answer was simple

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

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

}


You may also be able to do something like this:

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


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

精彩评论

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

关注公众号