Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6874551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:12:32+00:00 2026-05-27T04:12:32+00:00

I have the following navigation html/code now duplicated across several Views: <ul class=topNav> <li

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:12:33+00:00Added an answer on May 27, 2026 at 4:12 am

    Here are two ways to handle that.

    1. If you want a really reusable (Application independ solution) you should create a HtmlHelper Method
      Creating Custom HTML Helpers

    2. If you need it just in your Application consider doing something like that.

      public static class ControllerHelper
      {
      /// <summary>
      /// Checks the current action via RouteData
      /// </summary>
      /// <param name="helper">The HtmlHelper object to extend</param>
      /// <param name="actionName">The Action</param>
      /// <param name="controllerName">The Controller</param>
      /// <returns>Boolean</returns>
      public static bool IsCurrentAction(this HtmlHelper helper, string actionName, string controllerName)
      {
          string currentControllerName = (string)helper.ViewContext.RouteData.Values["controller"];
          string currentActionName = (string)helper.ViewContext.RouteData.Values["action"];
      
          if (currentControllerName.Equals(controllerName, StringComparison.CurrentCultureIgnoreCase) && currentActionName.Equals(actionName, StringComparison.CurrentCultureIgnoreCase))
              return true;
      
          return false;
      
      }
      }
      
      
      <ul class="topNav">
        <li @if(Html.IsCurrentAction("DashBoard", "DashBoard")) { <text>class="selected"</text> }>@Html.ActionLink("Dashboard", "Dashboard", new { id = ViewContext.RouteData.GetRequiredString("id") })</li>
        <li>@if(Html.IsCurrentAction("Stats", "Stats")) { <text>class="selected"</text> }>@Html.ActionLink("Stats", "Stats", new { id = ViewContext.RouteData.GetRequiredString("id") })</li>
      
      // ....
      </ul>
      

    Please tell me if you want to implement the first approach, i will provide more help

    hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code for framset display <FRAMESET ROWS=18%,* > <FRAME SRC=./views/Title_Page.html NAME=TITLE
I have the following HTML: <ul class="main-navigation"> <li class="left">&nbsp;</li> <li class="normal">Home</li> <li class="normal">Internet</li> <li
I have the following HTML code: <td class=myclass width=1% align=right ><a href=javascript:goToNav(); id=top><img id=navup
I'm using the following code to have a non-JS navigation: <ol id=navigation> <li id=home><a
Let me brief you the whole requirement first. I have the following HTML code:
I have a navigation, something like the following... <ul> <li><a href=page.html id=hyperlink1>Link</a> <ul> <li><a
Hello I have the following code to generate my navigation/page menu along with applying
I have come across the following code that looks at divs contained inside divWiz
I have the following bit o' jquery: // Code for Side Navigation $(#sideNav ul
I have navigation with following values: <a href=#home id=home class=goto>Home</a> <a href=#profile id=profile class=goto>Profile</a>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.