I have a ViewBag.IsLocal set to true in controller. I would like to use jquery to check the ViewBag value and display an alert.
Code:
if(@ViewBag.IsLocal == true)
{
alert("yeah");
}
I never get the alert. When I use Firebug to see the value of ViewBag it’s True ( with capital T). Do I have to do something like == ‘True’? I tried it all and none of that worked.
Thank you for help.
H
If you view source on the rendered page, what’s being inserted in place of your razor nugget? If
IsLocalis a bool type, I think you’ll see this:The reason for that is because
true.ToString()isTrue.In which case, you’ll need to make a string comparison there: