JavaScript 関数内で razor 変数を評価する必要があります。次のコードがあるとします。
@{var unseenNotificationsExist = false;}
@foreach(var notification in viewModel)
{
if (notification.WasSeen == false)
{
unseenNotificationsExist = true;
break;
}
}
unseenNotificationsExist
次のように JavaScript で変数を評価する必要があります。
if(@unseenNotificationsExist == true)
$('#unseenNotifCount').addClass('notifNotSeen');
ただし、JavaScript コードをデバッグすると、次のようになります。
if(True == true)
また、次のエラーが表示されます。
Uncaught ReferenceError True が定義されていません