Is there a better way to do this?
I have an HTML helper extension method that checks if the current tab menu is the the selected one and then chooses .selected css class or not. I put the html.IsSelected link in each li as
<li class='<%=Html.IsSelected(string a, string b)%>' >
where a is the tab name and b is ViewData assigned.
is this clean or is there a better way?
If you can live with a javascript solution, look at how the jQuery UI Accordion plugin handles this. Essentially, you can choose the highlighted tab based on the controller by examining the request url when the page is loaded.
Alternatively, you can set a ViewBag item for each tab that corresponds to the tab’s class value. Set the value for the current tab to the active css class and the others to empty (or their defaults). Then you can use:
In your controller, you would then set up the proper values for the ViewData variables.