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 pilation is turned off
Anyone could explain why this occurs and maybe guide me to a possible solution ?
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 pilation is turned off
Anyone could explain why this occurs and maybe guide me to a possible solution ?
Share Improve this question edited Aug 28, 2012 at 16:18 tereško 58.5k25 gold badges100 silver badges150 bronze badges asked Aug 28, 2012 at 15:46 Mihai LaboMihai Labo 1,0822 gold badges17 silver badges40 bronze badges2 Answers
Reset to default 3Try
if ('@Model.IsNew' == 'true') {
alert("Is New");
}
That's just the VS IDE failing to understand the mix of Razor and Javascript.
Your code will work fine.