0

My model property MobileNumber may have a value or may be null. I am trying to check for this within my View, using JS.

var mobileNumber =  @String.IsNullOrEmpty((Model.MobileNumber));

However the browser console doesn't like this:

Uncaught ReferenceError: True is not defined

It looks like its trying to assign True to the variable mobileNumber:

var mobileNumber =  True;

Any idea why this is not working? I can't do checks such as:

if (@Model.MobileNumber == null) because this ends up as if( == null).

when the value is null.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291

1 Answers1

0

Try the following code snippet:

 var mobileNumber =  @(String.IsNullOrEmpty(Model.MobileNumber) ? "true" : "false");

We are trying to assign True to variable mobilenumber in javascript. Without quotes, javascript will try to interpret TRUE as a value/expression. There is no value TRUE natively defined in javascript. It is "true" but javascript is case sensitive so it won't bind "TRUE" to true.

ScareCrow
  • 497
  • 3
  • 6