How to use Session variable object in foreach-MVC5 View

前端 未结 1 391
有刺的猬
有刺的猬 2020-12-20 08:53

I am working on dynamic menus. Using Session Variable by passing whole object. As can be seen from controller:

Session[\"PackageSbMenu2\"] = QueryHelper.Get_         


        
相关标签:
1条回答
  • 2020-12-20 09:29

    You need to cast your Session object

     @{    
        var menu = Session["PackageSbMenu2"] as List<MenusDM>;
        if(menu != null)
        {
            foreach(var t in menu)
            { 
             <li><a href=@Html.ActionLink(t.Controller, t.Action)>t.Name</a></li>
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题