I would like to set a JavaScript variable in my view (inside a script block) based on the existences of a ViewBag property from the controller... like:
var doAboutTab = @(ViewBag.DoAboutTab != null)
This generates a JavaScript error of:
var doAboutTab = False
'False is not defined'
@if(ViewBag.DoAboutTab != null)
{
var doAboutTab ="something";
}else
{
var doAboutTab ="something_else";
}
or
var doAboutTab = '@ViewBag.DoAboutTab' !== '';
The false keyword is lower case in javascript.
var doAboutTab = @((ViewBag.DoAboutTab != null).ToString().ToLower());
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