1
我有一個MVC項目,並且需要在視圖之間傳遞一個變量。我試圖使用會話變量來做到這一點,但當我嘗試設置它時,它保持爲空。我究竟做錯了什麼?所有這些代碼都在我的控制器中。會話變量保持爲空
public string searchQ
{
get { return (string)Session["searchQ"]; }
set { Session["searchQ"] = ""; }
}
public ActionResult Index()
{
Session["InitialLoad"] = "Yes";
return View();
}
[HttpPost]
public ActionResult Index(string heatSearch)
{
ViewBag.SearchKey = heatSearch;
searchQ= heatSearch;
return View();
}
public ActionResult Index_Perm()
{
ViewBag.SearchKey = searchQ;
return View();
}
目標是在視圖之間傳遞該搜索關鍵字。
感謝您的幫助。還有一件事,當我點擊鏈接來加載頁面Index_Perm時,searchQ再次爲空。 –
@Danger_Fox AFAIK,應該解決它,但這個問題提供了一些技巧:http://stackoverflow.com/questions/10629882/asp-net-mvc-session-is-null –