I am programming a website with ASP.NET MVC using C#. I have ul li,
with a few tabs, I want to get the query string and check the value, according to the query string value, I want to make a li
active
<li >
<a ordering"] == "newest" ? 'active' : ''}" href="~/[email protected]["CatId"]&ordering=newest" role="tab" aria-controls="newest" aria-selected="true">newest</a>
</li>
<li >
<a ordering"] == "MostVisited" ? 'active' : ''}" href="~/[email protected]["CatId"]&ordering=MostVisited" role="tab" aria-controls="MostVisited" aria-selected="false">MostVisited</a>
</li>
<li >
<a ordering"] == "Most-Rank" ? 'active' : ''}" href="~/[email protected]["CatId"]&ordering=Most-Rank" role="tab" aria-controls="Most-Rank" aria-selected="false">Most-Rank</a>
</li>
<li >
<a ordering"] == "cheapest" ? 'active' : ''}" href="~/[email protected]["CatId"]&ordering=cheapest" role="tab" aria-controls="cheapest" aria-selected="false">cheapest</a>
</li>
but it doesn't work, what is the problem?
CodePudding user response:
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