MVC with Bootstrap Navbar - Set Selected Item to Active

后端 未结 7 1541
抹茶落季
抹茶落季 2020-12-13 10:05

I\'m learning Bootstrap and can\'t get the selected item into an \"active\" state. The active state remains on the default item. The newly selected/clicked item changes to

7条回答
  •  别那么骄傲
    2020-12-13 10:53

    Simplest thing to do is send a ViewBag parameter from your controllers like following;

    public ActionResult About()
        {            
            ViewBag.Current = "About";
            return View();
        }
    
    
        public ActionResult Contact()
        {            
            ViewBag.Current = "Contact";
            return View();
        }
    

    In the cshtml page do the following;

               
    

    Courtesy to @Damith in here

提交回复
热议问题