I have the following navigation html / code, which is now duplicated across multiple views:
<ul class="topNav"> <li class="selected">@Html.ActionLink("Dashboard", "Dashboard", new { id = ViewContext.RouteData.GetRequiredString("id") })</li> <li>@Html.ActionLink("Stats", "Stats", new { id = ViewContext.RouteData.GetRequiredString("id") })</li> <li>@Html.ActionLink("Questions", "Questions", new { id = ViewContext.RouteData.GetRequiredString("id") })</li> <li>@Html.ActionLink("Answers", "Answers", new { id = ViewContext.RouteData.GetRequiredString("id") })</li> <li>@Html.ActionLink("Contacts", "Contacts", new { id = ViewContext.RouteData.GetRequiredString("id") })</li> </ul>
Of course, in each view, class="selected"
li
changes. Is there an easy way to place this block of code in a partial or layout view?
Also, should I use ViewContext.RouteData.GetRequiredString("id")
to go to the id
parameter of the controller or is there an easier way?
source share