我想在我的 .net 核心 mvc 應用程序中使用 TempData。我關注了https://docs.microsoft.com/en-us/aspnet/core/fundamentals/app-state?view=aspnetcore-2.1#tempdata 中的文章我總是得到 NULL 這是我的代碼:public async Task<ActionResult> Index(RentalsFilter filter){ TempData["test"] = "ABC"; return View();}public ActionResult Create(){ var abc = TempData["test"].ToString(); return View();}
3 回答

青春有我
TA貢獻1784條經驗 獲得超8個贊
您是否按照文檔中的說明配置了 TempData:
在 ConfigureServices 方法中添加:
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
.AddSessionStateTempDataProvider();
services.AddSession();
在 Configure 方法中,您應該添加:
app.UseSession();
- 3 回答
- 0 關注
- 263 瀏覽
添加回答
舉報
0/150
提交
取消