javascript - MVC - pass ViewData as boolean -
sorry newbie question.
when passing boolean value controller view using viewdata, how retrieve boolean value in javascript? example:
controller:
viewdata["login"] = true;
view
<script type="text/javascript"> var login = <%= (bool)viewdata["login"] %>; /// doesn't work, throw javascript error; </script>
yeh surely can do
<script type="text/javascript"> var login = '<%= viewdata["login"] %>'; /// login string 'true' </script>
but rather keep login object boolean rather string if that's possible
thanks!
just remove single quotes.
<script type="text/javascript"> var login = <%= (bool)viewdata["login"] ? "true" : "false" %>; </script>
this result in:
var login = true;
which parsed boolean in browser.
Comments
Post a Comment