I am passing a boolean value to a javascript function in my .net mvc action page.
problem is, it is outputting the value True and javascript apparently only accepts ‘true’ (in lower case).
I don’t want to hack the variable and make it a string and convert it to lower case in my action, but it looks like I have no choice?
If you’re using the ToString() method on a .NET boolean to send the value to Javascript, try replacing it with something like
so that it gets sent to Javascript as the appropriate string representation of the required bool value.
EDIT: Note the difference between:
and
In the first example, you end up with:
and that’s a literal Boolean false. In the second, you end up with:
and in JavaScript, ‘false’ is a non-empty string and consequently if evaluated in a Boolean context, it’ll be true. Well, true-ish. 🙂