對於HttpContext.Items有限制嗎?如果是的話,替代方案是什麼?單擊鏈接後MVC HttpContext.Current.Items爲空
在FirstController索引視圖我正在設置一個項目。
public class FirstController : Controller
{
public ActionResult Index()
{
HttpContext.Items["Sample"] = "DATA";
return View();
}
}
<a href="/SecondController/TestView">Sample Link</a>
當我試圖讓在值SecondController它給我空的,而不是「DATA」
public class SecondController : Controller
{
public ActionResult TestView()
{
string text = HttpContext.Current.Items["Sample"];
return View();
}
}
我不想使用會話。這可以使用自定義屬性來完成嗎? – CoolArchTek
自定義屬性不會解決您的問題。解釋爲什麼你不想使用會話,請點擊「[在asp.mvc中請求之間存儲數據的正確方式](http://stackoverflow.com/questions/15336991/what-is-correct-way -of-storage-data-between-requests-in-asp-mvc)「鏈接來查看備選方案。 – CodeCaster