Using Session variable within foreach

Tal Rofe

Is it possible to use foreach in cshtml file, and use the Session variable?

I want to do something like this:

@foreach (var item in Session["Cart"])

Is it possible?

M Goward
if(Session["Cart"] != null)
{
    foreach (var item in (Session["Cart"] as List<[type]>))
    {
       //do whatever you need to do
    }
}

So the answer is yes

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related