i’m having issues implenting a dynamic action-based menu system in a PartialView as below:
<ul class="tabs">
<li <% if (ViewContext.RouteData.Values["Action"] == "Index"){ %>class="active"<% } %>><a href="/talent">Home</a></li>
<li <% if (ViewContext.RouteData.Values["Action"] == "account"){ %>class="active"<% } %>><a href="/talent/account">Account settings</a></li>
<li <% if (ViewContext.RouteData.Values["Action"] == "password"){ %>class="active"<% } %>><a href="/talent/password">Password settings</a></li>
<li <% if (ViewContext.RouteData.Values["Action"] == "profile"){ %>class="active"<% } %>><a href="/talent/profile">Edit profile</a></li>
<li <% if (ViewContext.RouteData.Values["Action"] == "messages"){ %>class="active"<% } %>><a href="/talent/messages">Messages</a></li>
<li id="logout"><a href="/logout">Logout</a></li>
</ul>
The problem is that only the ‘Index’ menu item works, where the CSS class is rendered in the HTML markup. The others don’t, really strange. Any ideas??
All action methods other than Index specified with lowcase. Use case insensitive comparison instead of “==”