title: Adding class to div based on ViewBag.Title value in _layout.cshtml file
body: <p>I am working on a asp .net razor page application . I have a navbar in _layout.cshtml file which contain some links. I want to assign active class to link which is clicked. I am trying to do so by verifying value of ViewBag.Title but its not working but I am getting its value in console. Please help me.
  Here is my navbar link part in _layout.cshtml file.</p>
  <pre><code>  &lt;div class=&quot;navbar-nav ms-auto&quot;&gt;
                          &lt;a data-toggle=&quot;tab&quot; asp-page=&quot;Index&quot; class=&quot;nav-item nav-link   @ViewBag.Title=='Welcome'? ' active' : '' &quot;&gt;Home&lt;/a&gt;
                          &lt;a data-toggle=&quot;tab&quot;  asp-page=&quot;Products&quot; class=&quot;nav-item nav-link {{ @ViewBag.Title=='Products'  ? 'active' : '' }}&quot;&gt;Products&lt;/a&gt;
                          &lt;a data-toggle=&quot;tab&quot; asp-page=&quot;NewsBlog&quot; class=&quot;nav-item nav-link {{ @ViewBag.Title=='News &amp; Blog'  ? 'active' : '' }} &quot;&gt;News &amp;amp; Blog&lt;/a&gt;
                          &lt;a data-toggle=&quot;tab&quot; asp-page=&quot;Contact&quot; class=&quot;nav-item nav-link {{ @ViewData[&quot;Title&quot;]=='Contact us'  ? 'active' : '' }}&quot;&gt;Contact Us&lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  <p>here is Index page which assigns value to viewBag</p>
  <pre><code>@page
  @model Sora.UI.Pages.IndexModel
  @{
       ViewBag.Title= &quot;Welcome&quot;;
  }
  </code></pre>