Javascript MVC ASP.NET simple if condition not working -
i've following asp.net mvc razor view code doesn't seem working:
@{    bool condition1=model.someobject.condition1;   bool condition2 = model.someobject.condition2; }  if('@condition1') {     alert('hi condition1'); } else if ('@condition2') {     alert('hi condition2'); } else {      alert('hi condition3');  }  here not working:
- when condition2 true javascript 'hi condition2' never hit.
i tried below , still not working.
else if ('@condition2' ==true){
am missing casting here, please?
thank you.
according code alert('hi condition2') should work when condition1 == false , condition2 == true.
 in addition, shouldn't wrap @condition1 , @condition2 in quotes '. bool, not string.
 matter in javascript condition not empty string equals true.
 1 more thing: .net bool converts string true or false (in upper case). in other side, js bool values true , false.
 try:  
if (@(condition.tostring().tolower())) { ... } 
Comments
Post a Comment