KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
In the default asp.net mvc project, in the Site.Master file, there is a menu navigation list: <div id="menucontainer"> <ul id="menu"> <li><%= Html.ActionLink("Home", "Index", "Home")%></li> <li><%= Html.ActionLink("About Us", "About", "Home")%></li> </ul> </div> This renders in the browser to: <div id="menucontainer"> <ul id="menu"> <li><a href="/">Home</a></li> <li><a href="/Home/About">About Us</a></li> </ul> </div> I want to be able to dynamically set the active list item, based on the view that is being called. That is, when the user is looking at the home page, I would want the following HTML to be created: <div id="menucontainer"> <ul id="menu"> <li class="active"><a href="/">Home</a></li> <li><a href="/Home/About">About Us</a></li> </ul> </div> I would expect that the way to do this would be something like: <div id="menucontainer"> <ul id="menu"> <li <% if(actionName == "Index"){%> class="active"<%}%>><%= Html.ActionLink("Home", "Index", "Home")%></li> <li <% if(actionName == "About"){%> class="active"<%}%>><%= Html.ActionLink("About Us", "About", "Home")%></li> </ul> </div> The key bit here is the <% if(actionName == "Index"){%> class="active"<%}%> line. I do not know how to determine what the current actionName is. Any suggestions on how to do this? Or, if I'm on completely the wrong track, is there a better way to do this?
Tags (comma-separated)
Save Edits
Cancel