if in the Site.Master
file we have something like
<div id="menu-container">
<ul id="menu">
<li>
<%: Html.ActionLink("Frontpage", "Index", "Home")%></li>
<li>
<%: Html.ActionLink("Content", "Index", "Content")%></li>
<li>
<%: Html.ActionLink("Winners", "Index", "Winners")%></li>
<li>
<%: Html.ActionLink("Users", "Index", "Users")%></li>
<li>
<%: Html.ActionLink("Statistics", "Index", "Statistics")%></li>
<li>
<%: Html.ActionLink("Help", "Help", "Home")%></li>
</ul>
<ul id="publish">
<li>
<%: Html.ActionLink("Preview", "Index", "Preview")%></li>
</ul>
</div>
and we want, in each Content page set the correct class="selected"
attribute to the right <li>
what would be the best way?
Currently I'm using:
<% string url = Page.Request.Url.AbsoluteUri.ToString(); %>
<ul id="menu">
<li <% if (url.Contains("/Home")) { Response.Write("class='selected'"); } %>>
<%: Html.ActionLink("Frontpage", "Index", "Home")%></li>
<li <% if (url.Contains("/Content")) { Response.Write("class='selected'"); } %>>
<%: Html.ActionLink("Content", "Index", "Content")%></li>
<li <% if (url.Contains("/Winners")) { Response.Write("class='selected'"); } %>>
<%: Html.ActionLink("Winners", "Index", "Winners")%></li>
<li <% if (url.Contains("/Users")) { Response.Write("class='selected'"); } %>>
<%: Html.ActionLink("Users", "Index", "Users")%></li>
<li <% if (url.Contains("/Statistics")) { Response.Write("class='selected'"); } %>>
<%: Html.ActionLink("Statistics", "Index", "Statistics")%></li>
<li <% if (url.Contains("/Home/Help")) { Response.Write("class='selected'"); } %>>
<%: Html.ActionLink("Help", "Help", "Home")%></li>
</ul>
but I don't think that is the best approach.
Thanks for any help