Reputation: 1082
I have tried several tactics to use the boolean value within the JS ,but nothing works :
<script type="text/javascript">
var model = @Html.Raw(Json.Encode(Model));
if (model.IsNew == true) {
alert("1");
}
</script>
Tried the following:
var IsNew = @Model.IsNew ;
var IsNew = "@Model.IsNew";
I keep getting the following error :
Conditional compilation is turned off
Anyone could explain why this occurs and maybe guide me to a possible solution ?
Upvotes: 3
Views: 4119
Reputation: 887413
That's just the VS IDE failing to understand the mix of Razor and Javascript.
Your code will work fine.
Upvotes: 2