Reputation: 14155
Inside my asp.net mvc4 app I have menus which is stored inside Shared folder as partial view like
<li class="menu-title">
<a class="title" href="#">Main menu</a>
</li>
<li class="submenu_items" style="display: list-item;">
<ul>
<li>
@Html.ActionLink("Index", "Index", "My Index")
</li>
<li>
@Html.ActionLink("About", "Index", "About")
</li>
</ul>
</li>
How can I send from controller some flag to the view where I would append css class to selected link, for example if visitor click first link (Index) when this page loads I want this menu partial to be
<li class="submenu_items" style="display: list-item;">
<ul>
<li>
@Html.ActionLink("Index", "Index", "My Index", new {@class="selected "})
</li>
<li>
@Html.ActionLink("About", "Index", "About")
</li>
</ul>
</li>
Upvotes: 0
Views: 132
Reputation: 9764
To highlight a selected menu, We can make use of custom Html helper, Scott has written an wonderful article on this check this link
http://odetocode.com/Blogs/scott/archive/2012/08/25/asp-net-mvc-highlight-current-link.aspx
Upvotes: 1