I\'m new to MVC. I want to be able to hide some actionlinks for some users. Say I have a \"create\" actionlink which I only want administrators to see and click. I want to u
The solution suggested by Richard is really beautiful, though as Matthieu noted someone might need extra html code to be rendered (or not rendered) as well. Thus Matthieu's solution seems to be more widely applicable, I would just centralize the logic regarding which users are considered admins in extension method.
Extension method:
public static bool IsAdmin(this WebViewPage page)
{
return page.User.IsInRole(@"Domain\ProjectAdmins");
}
Usage:
@if (this.IsAdmin())
{
@Html.ActionLink("Create New Version", "Create")
}