ASP.NET MVC does browser refresh make TempData useless?

前端 未结 6 1178
逝去的感伤
逝去的感伤 2020-12-29 15:20

If I redirect to a new page passing TempData to initialise the page it works fine, however if the user presses the refresh button in their browser the TempData is no-longer

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-29 16:21

    Tempdata is used across redirects so if you are refreshing the page that means you are making a separate request to the server so that is why your data gets lost. To persist this data call Tempdata.Keep("KeyofTempdata") method in the action to which you are redirecting. If you want to remove data use Tempdata.Remove("KeyofTempdata").

提交回复
热议问题