Q:

mvc5 razor check session value

I am trying to get session value in mvc5 razor as below
@{var cnt=Session["count"].ToString();}
@if (cnt == "0" || string.IsNullOrWhiteSpace(cnt))

This results in an error if there is no value for session.  How should this be checked

A:

Simply check if its null
@if (Session["count"] != null) { 
    //Do what you want 
}

