asp.net mvc 4 - Is it possible to have a contextually dependent menu in the master layout? -
i have shared file that's called _submenu.cshtml, needs implemented in of views, find cumbersome , possibly unnecessary(?).
therefore, i'm wondering if there's such thing 'proper' way implement contextually dependent menu in shared master layout file changes depending on rendered view in renderbody()?
should each individual controller handle this, or handled elsewhere?
you can create controller-specific _submenu.cshtml
, follows:
~/views/controller1/_submenu.cshtml ~/views/controller2/_submenu.cshtml ~/views/controller2/_submenu.cshtml
then in layout
:
@html.partial("_submenu")
the view-engine fetch appropriate _submenu
based on current controller.
alternatively, if insist on using single _submenu
partial, can switch
on current controller , render appropriate html:
<div id="menu"> @switch (this.viewcontext.routedata.values["controller"].tostring().tolower()) { case "controller1": <a href="#">controller 1 action</a> <a href="#">another controller 1 action</a> break; case "controller2": <a href="#">controller 2 action</a> <a href="#">another controller 2 action</a> break; } </div>
Comments
Post a Comment