In my mvc5 project to disable an action link for unauthorized users i did like this
@if (User.IsInRole("Admin") | User.IsInRole("Manager"))
{
@Html.ActionLink("Add New Record", "ProductTypeIndex", "ProductType")
}
But if there are many roles to check then this @if() gets long. How to avoid this? Do i need custom helpers for this(if so how can i approach it)? Help appreciated..
You could write your own extension method and use it in your code.
Now simply you could call this extension method like this:
While you could use these extension methods in views as well but try to avoid writing your apps logic in views as much as possible since views not unit testable easily.