How to check if ViewBag property is null or not exists

Solution 1:

You can check for null and execute your script.

@if (ViewBag.YourKey== null)
{
 //your code   
}

This will check that ViewBag.YourKey is null if you want to check it for not null you can change the if condition.