ASP.NET MVC does browser refresh make TempData useless?

前端 未结 6 1185
逝去的感伤
逝去的感伤 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 15:58

    TempData exists specifically to store the data for just one page load/action/redirect. If you need the data to persist after a refresh you should place it in the ViewData collection so long as the action that is serving the refresh request is the same one as was initially requested (i.e. the ViewData value was not added prior to a Redirect).

提交回复
热议问题