Create an Html helper and check the current roles of the user in his code:
public static class Html { public static string Admin(this HtmlHelper html) { var user = html.ViewContext.HttpContext.User; if (!user.IsInRole("Administrator")) {
UPDATED:
Or create a wrapper for a helper. Example for ActionLink (this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName):
public static class Html { public static string RoleActionLink(this HtmlHelper html, string role, string linkText, string actionName, string controllerName) { return html.ViewContext.HttpContext.User.IsInRole(role) ? html.ActionLink(linkText, actionName, controllerName) : String.Empty; } }
source share