C
C#2y ago
PatrickG

❔ how to write javvscript only if c# statement is true ??

how can I make this work
9 Replies
friedice
friedice2y ago
what's the context
PatrickG
PatrickGOP2y ago
i want to write javascript only if a c# boolean is true, context doesnt matter i basically need the c# synthax to turn off right after the { and turn back on before the }
friedice
friedice2y ago
is this a .razor file? .js? .cs? blazor wasm? react? django?
PatrickG
PatrickGOP2y ago
razor file this example might be simpler
PatrickG
PatrickGOP2y ago
friedice
friedice2y ago
@{
bool isObjectTrue = true;
}

@if (isObjectTrue)
{
<script>
alert("C# object is true");
</script>
}
@{
bool isObjectTrue = true;
}

@if (isObjectTrue)
{
<script>
alert("C# object is true");
</script>
}
would something like this work? I only have experience with wasm and using jsinterop
PatrickG
PatrickGOP2y ago
yes seems like it's working Thanks
Denis
Denis2y ago
Consider closing this issue with /close
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server