I am trying to receive bool values from ViewBag.
But the issue is that to receive value I am using:
var test = '@ViewBag.Test'
In this way value will be 'True'
or 'False'
(string). Of cource I can use something like if (test == 'True')
but, is there a way to get from ViewBag bool value dirrectly, or at least convert it?
EDIT:
I need to get ViewBag value in javascript part.
In controller code is
ViewBag.Test = true;
In View code is
var test=@(ViewBag.Test.ToString().ToLower());
console.log(test);
Now the data type of variable test is a bool. So you can use:
if(test)
alert('true');
else
alert('false')
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