After looking at how the Orange Tabs ASP.NET MVC demo handles tabs, they have something like:
View:
<ul id="menu">
<% if (Html.IsCurrentAction("Index", "Home")) { %>
<li class="active"><%= Html.ActionLink("Home", "Index", "Home")%></li>
<% } else { %>
<li><%= Html.ActionLink("Home", "Index", "Home") %></li>
<% }%>
<% if (Html.IsCurrentAction("About", "Home"))
{ %>
<li class="active"><%= Html.ActionLink("About", "About", "Home")%></li>
<% } else { %>
<li><%= Html.ActionLink("About", "About", "Home")%></li>
<% }%>
<% if (Html.IsCurrentAction("SampleTags", "Home"))
{ %>
<li class="active"><%= Html.ActionLink("Sample Tags", "SampleTags", "Home")%></li>
<% } else { %>
<li><%= Html.ActionLink("Sample Tags", "SampleTags", "Home")%></li>
<% }%>
</ul>
and a corresponding helper class:
namespace Helpers
{
public static class IsCurrentActionHelper
{
public static bool IsCurrentAction(this HtmlHelper helper, string actionName, string controllerName)
{
string currentControllerName = (string)helper.ViewContext.RouteData.Values["controller"];
string currentActionName = (string)helper.ViewContext.RouteData.Values["action"];
if (currentControllerName.Equals(controllerName, StringComparison.CurrentCultureIgnoreCase) && currentActionName.Equals(actionName, StringComparison.CurrentCultureIgnoreCase))
return true;
return false;
}
}
}
Does this seem like an elegant way to approach this problem? I've seen dozens of different ways from javascript to query strings, etc.
I don't like javascript because I want the website to be fine for non-js enabled browsers and the query string approach seems cludgey.