I'm trying to use razor c# in my javascript. However it's telling me: The name 'isReport' does not exist in the current context
My code is this:
<script type="text/javascript">
var isReport = false;
@if(Model.columns != null)
{
isReport = true;
}
alert(isReport);
if(isReport)
$("#reports").dataTable();
</script>
I'm trying to do the same this as in this post I think... Mix Razor and Javascript code
Thanks!
You can use @: on your isReport assignment (inside the if):
<script type="text/javascript">
var isReport = false;
@if(Model.columns != null)
{
@:isReport = true; //change is here
}
alert(isReport);
if(isReport)
$("#reports").dataTable();
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With