I have the following navigation html/code now duplicated across several 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 the class="selected" of the li is changed. Is there an easy way to place this block of code in a Partial View or Layout View?
Also, must I really use ViewContext.RouteData.GetRequiredString("id") to get to the id parameter of the controller or is there a simpler way?
Here are two ways to handle that.
If you want a really reusable (Application independ solution) you should create a HtmlHelper Method
Creating Custom HTML Helpers
If you need it just in your Application consider doing something like that.
Please tell me if you want to implement the first approach, i will provide more help
hope this helps