This will do what you want:
var claimFlagged = @(Html.Raw(Json.Encode(Model.Flagged)));
If you simply try to use something like this:
var claimFlagged = @(Model.Flagged);
it will actually generate True
or False
(note the capitalised T
and F
), rather than the more natural lowercase versions. Using the @(Html.Raw(Json.Encode(...)))
method results in the correct lowercase output.
I've made the assumption that you want to work directly with bools, rather than strings, in your JavaScript code. If you do actually want the output to be a string instead (i.e. "true"
or "false"
), simply surround the code with quotation marks:
var claimFlagged = "@(Html.Raw(Json.Encode(Model.Flagged)))";