asp.net mvc - Evaluate Razor variable in javascript -


i need evaluate razor variable inside javascript function. given following code:

 @{var unseennotificationsexist = false;}   @foreach(var notification in viewmodel)  {     if (notification.wasseen == false)     {       unseennotificationsexist = true;       break;     }  } 

i need evaluate unseennotificationsexist variable in javascript this:

 if(@unseennotificationsexist == true)         $('#unseennotifcount').addclass('notifnotseen'); 

however, when debug javascript code, this:

if(true == true) 

and uncaught referenceerror true not defined

var unseennotificationsexist = @(unseennotificationsexist?"true":"false") ; //the line above must part of view  if( unseennotificationsexist == true)         $('#unseennotifcount').addclass('notifnotseen'); //this can part of js file or alternatively , less  //preferably part of view 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -