TempData is not clearing as expected

本小妞迷上赌 提交于 2019-12-05 05:52:14

Just adding this as I said in my comment. I suggest to do

if (TempData["Success"] != null) 
    vm.Success = true;

Instead of

if (TempData.ContainsKey("Success"))
      vm.Success = true; 

... so it counts as a TempData read. Glad it worked. Regards

Microsoft has made a change to the behavior of TempData that we need to be aware of in MVC 2 and 3. TempData now no longer completely clears at the end of a controller action cycle. TempData can now (automatically and without you changing anything) persist through to other pages. TempData keys are now only cleared if they’ve been read. Furthermore, if you use RedirectResult or RedirectToRouteResult, they will persist even if they are read.

Here are more details: warning-mvc-nets-tempdata-now-persists-across-screens

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!