When passing boolean value from controller to the view using ViewData, how do I retrieve it as a boolean value in javascript?
example:
Controller:
ViewData["login"] = true;
View
<script type="text/javascript">
var login = <%= (bool)ViewData["Login"] %>; /// this doesn't work, throw javascript error;
</script>
yeh surely i can do
<script type="text/javascript">
var login = '<%= ViewData["Login"] %>'; /// now login is a string 'True'
</script>
But i rather keep login object as a boolean rather a string if that’s possible.
Just remove the single quotes.
This will result in:
Which will be parsed as a boolean in the browser.