I'm wanting to do some sub navigation on a test project that I'm doing for my own knowledge and I was wanting to possibly do the sub nav in partials and call a Render on the partial simply based on the controller used. I was trying to figure out how others do it and what the best way to determine the controller would be from within the_Layout.cshtml?
Again, I don't have anything specific that I'm using this for (so no code samples). It's simply for my own knowledge and didn't know the best way to accomplish this would be. At work we do some similar stuff, but it's strictly CSS and I don't like it personally...
I'm aware of the renderpartial and I use it throughout the website, but I'm curious if it's been used to determine navigation display and the means to do so... It's late and I'm tired so hopefully this makes sense. If it doesn't please ask!
what the best way to determine the controller would be from within the_Layout.cshtml?
You could fetch the current controller and action from the RouteData
:
@{
var controller = ViewContext.RouteData.GetRequiredString("controller");
var action = ViewContext.RouteData.GetRequiredString("action");
}
Your question is extremely vague, so it is difficult to provide you with more specific details but for generating navigation menus you could also use custom html helpers or even entire child actions (Html.Action
helper) depending on the complexity.