Reputation: 43
I have used following code to add css class:
<div id="123" class="tab-pane @{ if (some_condition) { Html.Raw("active"); }; } ">
But it did not work.
I hope for this result:
<div id="123" class="tab-pane active">
Upvotes: 4
Views: 6230
Reputation: 6379
This should do it:
<div id="123" class="tab-pane @if (some_condition) { <text>active</text> }">
Upvotes: 0
Reputation: 6866
@MichaelPerrenoud's answer is close. You need to wrap the whole conditional in parenthesis.
Using @() tells razor to output a string. So
<div id="123" class='tab-pane @(condition ? "active" : "")'>
Upvotes: 9
Reputation: 346
you can add javascript code
<script>
@if(true)
$('#123').addClass("active");
</script>
Upvotes: 0
Reputation: 67898
I believe you may be wanting to do this:
<div id="123" class='tab-pane @some_condition ? "active" : ""'>
Upvotes: 0