I have an MVC view that changes a few small UI elements based on the user's role. Currently it modifies the output using a few if() statements using a couple boolean values I sent to the view through the viewmodel. However, it doesn't seem like a very good approach, so what I'd like to do is move this all into either an HtmlHelper class or the controller itself. Here's the current code:
<% if ( Model.IsAdmin ) { %> <td> <% } %> <%--Opening tag for admin options--%>
<% if ( Model.IsAdmin ) { %> <%:Html.ActionLink("Delete", "Delete", new { id = Id})%> <% } %> <%--Admin options--%>
<% if ( Model.IsAdmin ) { %> </td> <% } %> <%--Closing tag for admin options--%>
There's a seperate spot where I show/hide the create new link as well
<% if ( Model.IsEditor || Model.IsAdmin ) { %>
<%:Html.ActionLink("Create New", "Create") %>
<% } %>
There might be a couple other of these situations as well.
So any HtmlHelper I would build would potentially need a couple overloads for the different cases, so it would probably need to be pretty flexible. I've just been going around and around in my head on the best approach to this, and it seems like a common problem that someone else would probably have come up with already...
Thanks!