Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get bool value from ViewBag on view?

Tags:

jquery

c#

viewbag

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.

like image 748
Olegs Jasjko Avatar asked Aug 19 '15 08:08

Olegs Jasjko


1 Answers

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')
like image 193
J Santosh Avatar answered Sep 29 '22 14:09

J Santosh