I do something similar to the following over simplified example ;-)
Controller:
public ActionResult Index()
{
ViewData["MainMenuOn"] = "Home";
return View();
}
public ActionResult About()
{
ViewData["MainMenuOn"] = "About";
return View();
}
public ActionResult Contact()
{
ViewData["MainMenuOn"] = "Contact";
return View();
}
View:
<ul id="main-menu">
<li class="<%= Html.MainMenuOn("Home") %>">... action link for home action ...</li>
<li class="<%= Html.MainMenuOn("About") %>">... action link for about action ...</li>
<li class="<%= Html.MainMenuOn("Contact") %>">... action link for contact action ...</li>
</ul>
Helper extension:
public static string MainMenuOn(this HtmlHelper html, string menuItem)
{
if ((html.ViewData["MainMenuOn"] != null) && (html.ViewData["MainMenuOn"] == menuItem))
return "on";
return "";
}
Then your css should be rather simple
ul#main-menu li
{
background: green;
}
ul#main-menu li.on
{
background: blue;
}
There are many ways to skin this cat... depending on your needs I would start looking at different ways to implement the HtmlHelper extension.
HTHs,
Charles