javascript - MVC - Add / Remove a style when the user arrives on, or leaves, the home page -


i have mvc app, _layout.cshtml page looks follows (only showing relevant part):

<body>     <div id="wrapper">         <div class="navbar navbar-inverse navbar-fixed-top container" style="background-image: url(/images/headerbar.png); background-size: cover;">             <div class="container">                 <div class="navbar-header"> 

when user leaves home page, want style see in div present. however, when user arrives on home page, want style removed. there clean , simple way this?

in _layout.cshtml can check viewcontext.routedata["action"] or viewcontext.routedata["controller"] or viewcontext.controller.gettype() values , conditionally something.

for example:

<div class="navbar navbar-inverse navbar-fixed-top container" id="sidebar" style="@(viewcontext.controller.gettype() == typeof (homecontroller) ? "background-image: url(/images/headerbar.png); background-size: cover;" : "")">     <p> stuff here</p> </div> 

i additionally recommend using class instead of inline style.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -