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 6155425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:26:01+00:00 2026-05-23T20:26:01+00:00

For setting that I use Html helper method which is not the best imo,

  • 0

For setting that I use Html helper method which is not the best imo, because I use static field.

public enum CurrentState
{
    BeforeCurrent,
    AfterCurrent
}

public static CurrentState currentState = CurrentState.BeforeCurrent;

public static MvcHtmlString ActiveActionLink(this HtmlHelper helper, string linkText, string actionName, string controllerName, bool checkAction = true)
{
    string currentAction = helper.ViewContext.RouteData.GetRequiredString("action");
    string currentController = helper.ViewContext.RouteData.GetRequiredString("controller");

    if ((controllerName == currentController) && checkAction && (actionName == "Index"))
    {
        currentState = CurrentState.BeforeCurrent;
    }

    if ((controllerName == currentController) && checkAction && (actionName != currentAction))
    {
        if (currentState == CurrentState.BeforeCurrent)
        {
            return helper.ActionLink(linkText, actionName, controllerName, null, new { @class = "beforeCurrent" });
        }
        else if (currentState == CurrentState.AfterCurrent)
        {
            return helper.ActionLink(linkText, actionName, controllerName, null, new { @class = "afterCurrent" });
        }
    }

    if ((controllerName == currentController) && (!checkAction || (actionName == currentAction)))
    {
        currentState = CurrentState.AfterCurrent;
        return helper.ActionLink(linkText, actionName, controllerName, null, new { @class = "current" });
    }

    return helper.ActionLink(linkText, actionName, controllerName);
}

I have two levels of menus and that’s why I use checkAction parameter:

  • main menu – @Html.ActiveActionLink(Resources.Global.mainMenuBoard, “Index”, “Board”, checkAction: false)
  • side menu – @Html.ActiveActionLink(@Resources.Global.managementOverview, “Index”, “Management”)

and in side menu I need to know if it’s after and before current (overlapping items…).

Is it a way to improve that?
Additionally I must say that I use javascript also for that but it must work also for javascript disabled.

  • 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-23T20:26:01+00:00Added an answer on May 23, 2026 at 8:26 pm

    I finally solve that by generating whole menu in one helper:

    public class Link
    {
        public string LinkText { get; set; }
        public string ActionName { get; set; }
    }
    
    public static List<MvcHtmlString> SubMenuLinks(this HtmlHelper helper, string controllerName, List<Link> links)
    {
        List<MvcHtmlString> menuElements = new List<MvcHtmlString>();
        string actualCssClass = "beforeCurrent";
    
        string currentAction = helper.ViewContext.RouteData.GetRequiredString("action");
        string currentController = helper.ViewContext.RouteData.GetRequiredString("controller");
    
        foreach (Link link in links)
        {
            if (controllerName == currentController && link.ActionName == currentAction)
            {
                menuElements.Add(helper.ActionLink(link.LinkText, link.ActionName, controllerName, null, new { @class = "current" }));
                actualCssClass = "afterCurrent";
            }
            else
            {
                menuElements.Add(helper.ActionLink(link.LinkText, link.ActionName, controllerName, null, new { @class = actualCssClass }));
            }
        }
    
        return menuElements;
    }
    

    and in view:

    @{
        List<MvcHtmlString> actionMenu = Html.SubMenuLinks("Manager", new List<Link>()
        {
            new Link() { LinkText = "linkText", ActionName = "actionName" },
            new Link() { LinkText = "linkText2", ActionName = "actionName2" }
        });
    }
    @section SideMenu
    {
        @for (int i = 0; i < actionMenu.Count; i++) 
        { 
            <li id="menu@(i)">@actionMenu.ElementAt(i)</li>
        }
    }
    

    Not perfect, but it works at least.

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

Sidebar

Related Questions

My database schema has a 'locked' setting meaning that the entry can not be
I'm working on a little html/css framework that I can use for most of
I'm having trouble setting fixed widths on columns which use colspan . It seems
We are about to break our controllers up: actions that return semi-static HTML pages,
I have an iFrame that I use to display different media types by setting
Under VS's external tools settings there is a Use Output Window check box that
I know about Allow Triggers to Fire Others server setting that allows the action
I want to know if Netbeans has some option or setting that will allow
I heard that setting index is closely related to the sequence of joining tables.
Documentation simply states that setting setAutosavingDelay to anything > 0 on the shared doc

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.