I'm not sure whats wrong with my if statement. I'm trying to use my model inside my javascript.
if (@Model !== null)
{
if (@Model.Level !== null)
{
//use @Model.Level
}
}
else
{
//use default
}
The Model is null, but it still steps into the first if statement (and breaks on the second one obviously). I've tried @Model, !@Model and != but it still always steps in.
What am I doing wrong? (It's also got squiggly red lines under both !== saying there is a syntax error)
if(@Model && @Model.Level) { ... }. I believe you're breaking becauseundefined !== null. I'm betting your values areundefinedinstead ofnull. Try the truthy/falsy syntax above.if(@Model)instead of comparing it tonull, that way this picks upundefinedas well!=instead of!==