C
C#14mo ago
PatrickG

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

how can I make this work
9 Replies
friedice
friedice14mo ago
what's the context
PatrickG
PatrickG14mo 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
friedice14mo ago
is this a .razor file? .js? .cs? blazor wasm? react? django?
PatrickG
PatrickG14mo ago
razor file this example might be simpler
PatrickG
PatrickG14mo ago
friedice
friedice14mo 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
PatrickG14mo ago
yes seems like it's working Thanks
Denis
Denis14mo ago
Consider closing this issue with /close
Accord
Accord14mo 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.