First, I will consider a specific question, and then an abstract:
Concrete
One possible way would be to create a set of HTML helpers or user controls that have some basic logic to determine if they should be visible. For example, your use may be:
<td> Html.LinkList(", " ActionLinks.ViewDetails(item), ActionLinks.DeleteAndConfirm(item), ActionLinks.Approve(item)) </td>
Each action contains its own logic to determine whether it should be used (for example, βI require administrator rightsβ), and if this action defines its own criteria, you do not need to return string.Empty :
class ActionLinks { public static string Approve(Item item) { if(ItemRequiresApproval(item) && CurrentUserIsAdmin()) { return Html.ActionLink("Approve", "Approve", new { id = item.Mail_ID }); } else { return string.Empty; } } private static bool ItemRequiresApproval(Item item) {
LinkList will look something like this:
string LinkList(string delimiter, params string[] links) { StringBuilder sb = new StringBuilder(); foreach(string link in links) { if(!string.IsNullOrEmpty(link)) { sb.Append(delimiter); sb.Append(link); } } return sb.ToString().Substring(delimiter.Length); }
annotation
The solution to your problem is to remember SRP (the principle of shared responsibility) and SOC (Separation of problems) . In your current example, your view is a class. You have made this class responsible not only for the overall markup structure, but also for every tiniest detail of almost your entire application! Your look should not know or care about administrator rights or approval. Only approving buttons should know about approval. Only administrator-specific items should be aware of administrator rights. If you find that you are repeating certain types of checks (for example, "if admin is show x, otherwise show y"), create some common wrappers, such as the AdminPanel, that will turn on or off accordingly. For all other players, this element is simply or not - and this element is responsible for making this decision.