如何在ASP.NETMVC 4應用程序中使用我是ASP.NETMVC的新手。我以前使用過PHP,很容易根據(jù)當前會話變量創(chuàng)建會話并選擇用戶記錄。我在互聯(lián)網(wǎng)上到處尋找一個簡單的逐步教程,它可以向我展示如何在我的C#ASP.NETMVC 4應用程序中創(chuàng)建和使用會話。我希望用戶變量創(chuàng)建一個會話,我可以從控制器中的任何地方訪問這些變量,并且能夠在LINQ查詢中使用這些變量。-提前謝謝!
3 回答

阿晨1998
TA貢獻2037條經(jīng)驗 獲得超6個贊
試一試
//adding data to session
//assuming the method below will return list of Products
var products=Db.GetProducts();
//Store the products to a session
Session["products"]=products;
//To get what you have stored to a session
var products=Session["products"] as List<Product>;
//to clear the session value
Session["products"]=null;
- 3 回答
- 0 關注
- 249 瀏覽
添加回答
舉報
0/150
提交
取消