I have a simple ViewModel:
public class IndexViewModel
{
public bool ShowWelcomeMsg { get; set; }
}
And in my view I need this property in JS:
<script type="text/javascript">
var ShowWelcomeMsg = @Model.ShowWelcomeMsg;
</script>
But that's not correct because it outputs False
instead of false
but anyway, the question is more generic because I want to know the solution for int, string, etc as well:
What is the correct way to encode a viewmodel property to use it in JavaScript (in Razor)?