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
Post a Comment