I need to evaluate a razor variable inside a JavaScript function. Given the following code:
@{var unseenNotificationsExist = false;}
@foreach(var notification in viewModel)
{
if (notification.WasSeen == false)
{
unseenNotificationsExist = true;
break;
}
}
I need to evaluate the unseenNotificationsExist variable in JavaScript like this:
if(@unseenNotificationsExist == true)
$('#unseenNotifCount').addClass('notifNotSeen');
However, when I debug the JavaScript code, I get this:
if(True == true)
and also I get the following error:
Uncaught ReferenceError True is not defined