@if (Roles.IsUserInRole(\"Administrators\"))
{
@Html.ActionLink(\"Create New\", \"Create\")
}
I have bounch of roles for use
I would write a custom action link helper:
public static class LinkExtensions
{
public static IHtmlString ActionLinkIfInRole(
this HtmlHelper htmlHelper,
string roles,
string linkText,
string action
)
{
if (!Roles.IsUserInRole(roles))
{
return MvcHtmlString.Empty;
}
return htmlHelper.ActionLink(linkText, action);
}
}
and then in my views:
@Html.ActionLinkIfInRole("Administrators", "Create New", "Create")