ASP.NET MVC: handling logic & variables in the _Layout page -


in _layout.cshtml page, i've got elements need hidden on pages. know pages on won't display parts. single page, this:

@if (viewcontext.routedata.values["action"].tostring() != "login") {     <div> .... <div> } 

but gets messy , long multiple pages. someplace, ideally not in _layout page, build list of actions, , if current action of them, set boolean variable (showstuff) false. on _layout:

@if (showstuff== true) {     <div> .... <div> } 

i'm not sure best-practice way examine list of actions , set boolean. can _layout page have it's own model , controller normal view?

if devs stop looking 'best way' every problem have, great. no best way here, opinionated solutions. here's mine: can create action filter [shownav] , decorate controller/action need. filter put boolean httpcontext.items . create htmlhelper checks boolean. in _layout, if (html.canshownavig()) { <nav> } . that's easiest solution comes mind.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -