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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T06:55:50+00:00 2026-05-19T06:55:50+00:00

OK new to MVC. I had asked this question earlier and got an answer

  • 0

OK new to MVC. I had asked this question earlier and got an answer but I am wondering if there is a simpler solution.

Say I have a master page with a menu laid out as an unordered list. How would I go about setting a css class on the currently selected menu item?

EDIT:

I am using the menu just as it comes setup out of the box when you start a new mvc app

<ul id="menu">              
   <li><%: Html.ActionLink("Home", "Index", "Home")%></li>
   <li><%: Html.ActionLink("About", "About", "Home")%></li>
</ul>
  • 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-19T06:55:52+00:00Added an answer on May 19, 2026 at 6:55 am

    The answer from Jakub Konecki led me in the right direction… here is the controller action I ended up with:

        [ChildActionOnly]
        public ActionResult MainMenu()
        {
            var items = new List<MenuItem>
            {
                new MenuItem{ Text = "Home", Action = "Index", Controller = "Home", Selected=false },
                new MenuItem{ Text = "My Profile", Action = "Index", Controller = "Profile", Selected = false},
                new MenuItem{ Text = "About", Action = "About", Controller = "Home", Selected = false }
            };
    
            string action = ControllerContext.ParentActionViewContext.RouteData.Values["action"].ToString();
            string controller = ControllerContext.ParentActionViewContext.RouteData.Values["controller"].ToString();
    
            foreach (var item in items)
            {
                if (item.Controller == controller && item.Action == action)
                {
                    item.Selected = true;
                }
            }
    
            return PartialView(items);
        }
    

    Hope this helps someone.

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

Sidebar

Related Questions

I am new to Spring MVC. But I had certain experience in working with
I am new to MVC 3 and have this question to start with, I
I'm kinda new to the asp.net-mvc framework and I was wondering whether anyone had
This question is next to the question I had asked here . I am
New to MVC, so hopefully this will be pretty simple. I have an HTML
I am new to MVC and have a grasp of the basic model, but
i see the new feature of areas in asp.net-mvc 2. it got me thinking.
Earlier I had similar issue. I have created asp mvc default template project and
Apologies, I'm new to ASP.NET MVC. :) I'm unsure if this is simple a
I just got a new development box and am having issues getting my MVC

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.