The goal
There is a shopping cart in my application and I need to check if it is empty or not.
The problem
Look:
@if (Session["ProductsSummary"] == null)
{
// Do something
}
As you can see, this piece of code checks if the session is null. When I add something to my cart — for the first time —, I create a session (called ProductsSummary
) and store something in it (some information about the product that was added).
When I remove this item from Shopping Cart
(or ProductsSummary
— as you wish), I remove it from the session, but the session still alive. In other words, the session isn't null anymore, but is empty.
What I need is simple: how can I check if a session is empty?
Technical details
I'm using C#.NET + MVC 4 + Razor Engine.
Just to knowledge
I'm working with KnockoutJS.