I am using MVC 5, I need to show and hide the links based on the logged in user role.
view code
if (User.IsInRole("Admin"))
{
@Html.ActionLink("Manage Users", "ManageUsers", new { id = Model.id, appname = Model.app_name })
}
controller code
[HttpPost]
[Authorize(Roles = "Admin")]
public ActionResult ApplicationEdit()
{
//////////////
}
hide the link when I logged in as a normal user, it works perfectly. But when I logged in as Admin it is not showing the link. hide the link both time. my requirement is hide the link only when logged in as a normal user not Admin.
Jignesh TrivediPosted Mar 18, 2015, 12:17 AM
Hi,
your code is correct it must work
check return value of User.IsInRole("Admin") when admin user login....
also use @ before if
@if (User.IsInRole("Admin"))
{
@Html.ActionLink("Manage Users", "ManageUsers", new { id = Model.id, appname = Model.app_name })
}
hope this will help you.