MVC with Bootstrap Navbar - Set Selected Item to Active

后端 未结 7 1515
抹茶落季
抹茶落季 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 11:02

    Your javascript function should work fine... The issue is that your links route to a controller and reload the entire page. In order to avoid this behavior you could render your body content as a partial view, that way the navbar elements do not reload. You shouldn't have to write a function to handle dom events - that is what javascript is for.

    To see what I mean, change your code:

  • About
  • Students Sample
  • to:

     
  • About
  • Students Sample
提交回复
热议问题