Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

making an li active according querystring value

I am programming a website with MVC c#,I have ul li, with a few tabs, I want to get the querystring and check the value , according of querystring value , I want to make a li be active

 <li class="nav-item">
     <a class="nav-link @{Context.Request.Query["ordering"] == "newest" ? 'active' : ''}" href="~/products?CatId=@Context.Request.Query["CatId"]&ordering=newest" role="tab" aria-controls="newest" aria-selected="true">newest</a>
  </li>
  <li class="nav-item">
      <a class="nav-link @{Context.Request.Query["ordering"] == "MostVisited" ? 'active' : ''}"  href="~/products?CatId=@Context.Request.Query["CatId"]&ordering=MostVisited" role="tab" aria-controls="MostVisited" aria-selected="false">MostVisited</a>
  </li>
                   
   <li class="nav-item">
       <a class="nav-link @{Context.Request.Query["ordering"] == "Most-Rank" ? 'active' : ''}" href="~/products?CatId=@Context.Request.Query["CatId"]&ordering=Most-Rank" role="tab" aria-controls="Most-Rank" aria-selected="false">Most-Rank</a>
   </li>

    <li class="nav-item">
        <a class="nav-link @{Context.Request.Query["ordering"] == "cheapest" ? 'active' : ''}" href="~/products?CatId=@Context.Request.Query["CatId"]&ordering=cheapest" role="tab" aria-controls="cheapest" aria-selected="false">cheapest</a>
    </li>

but it doesn’t work, what is the problem

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Can you try to replace @{Context.Request.Query["ordering"] == "MostVisited" ? 'active' : ''}" by @(Context.Request.Query["ordering"] == "MostVisited" ? 'active' : '')" ?

If it is Razor template, then the right syntax is @(expression), not @{expression}.

Regards

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading