I am new in ASP.NET Core. I have a navigation menu and I would like to track the active item. My idea is to use the action and controller names as navigation keys:
<
I would like to add something small that has perhaps been overlooked... Just add some embedded code in the layouts page at the top, before the HTML begins...
@{
var controller = ViewContext.RouteData.Values["Controller"];
var action = ViewContext.RouteData.Values["Action"];
}
The code is pretty self-explanatory... Then call the variables' values from anywhere within your code just as they are, like the way I did as shown below:
I found this method to be much simpler and hassle-free than aforementioned methods. Cheerio ;)