In Asp.Net MVC we can add class conditionally as following code:
<div class="choice @(Model.Active?"active":"")">
</div>
How can do this by using tagHelper and by remove else part in condition.
In Asp.Net MVC we can add class conditionally as following code:
<div class="choice @(Model.Active?"active":"")">
</div>
How can do this by using tagHelper and by remove else part in condition.
Ability to add a conditional css class by following tagHelper provides. this code like AnchorTagHelper asp-route-* for add route values acts.
in _ViewImports.cshtml add reference to taghelper as following
Use tagHelper in View:
result for Active = true and Display = true is:
There's no default way to do what you're asking. You would have to write a TagHelper that did that logic for you. Aka
And then the HTML would look like: