i am finding more and more my asp.net mvc views are starting to look like my old crappy asp code that i could never maintain or keep clean with integrated <% %> and html put together. below i have a code sammple of what i am talking about. is there any best practice or recommended way of avoiding this and keeping the views more maintable and readable.
<td>
<%
bool userRequiresApproval = false;
if (!string.IsNullOrEmpty(item.loginName))
{
MembershipUserCollection membership = (MembershipUserCollection)ViewData["UnapprovedUsers"];
if (membership != null && membership[item.loginName] != null)
{
userRequiresApproval = true;
}
}
bool isLoggedInUserAdmin = false;
if (ViewData.ContainsKey("isAdmin"))
{
isLoggedInUserAdmin = (bool)ViewData["isAdmin"];
}
if (isLoggedInUserAdmin && userRequiresApproval)
{%>
<%= Html.ActionLink("View", "Details", new { id=item.Mail_ID })%>, <%= Html.ActionLink("Delete", "GotoDeleteConfirmPage", new { id = item.Mail_ID })%>, <%= Html.ActionLink("Approve", "Approve", new { id = item.Mail_ID })%>
<%}
else if (isLoggedInUserAdmin)
{%>
<%= Html.ActionLink("View", "Details", new { id = item.Mail_ID })%>, <%= Html.ActionLink("Delete", "GotoDeleteConfirmPage", new { id = item.Mail_ID })%>
<%}
else
{%>
<%= Html.ActionLink("View", "Details", new { id = item.Mail_ID })%>
<%}%>
</tr>
<% } %>