I have .net mvc3 web site. And i must to implement top menu. Each of the menu tags is lead to his action and display another view.This what i have now:
<ul id="menu">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("Products", "Products", "Home")</li>
<li>@Html.ActionLink("Pricing", "Pricing", "Home")</li>
<li>@Html.ActionLink("Our Team", "OurTeam", "Home")</li>
<li>@Html.ActionLink("Contact Us", "ContactUs", "Home")</li>
</ul><!-- /menu -->
This view is Html.RenderAction("Header", "Home"); in my layout(because it must to appear in all pages)
I need to implement Custom ActionLink. The anchor text must be:
<span>text</span><b>text</b>
The “text” is Home(for example of first li)
And the current ActionLink must add class :”Selected” to the anchor.
How i can do this? Help please
p.s
I can add this menu for each view in my website with “selected” class of current view, but this is not good solution.
If I understand right you want to put the “selected” class to the current displaying action.
You can do a check in the view by looking at this:
Then you put the “selected” class to your actionlink the way showed in the previous answer
Personally I will create a ViewModel containing a list of “MenuAction” that expose, other than the route values, a bool property “Selected”. Imo from the view will be much more cleaner the handling of the data.