ASP.Net MVC TempData - how to save state

We use ASP.Net MVC TempData to store form data between page updates. We have a button on the page that allows the user to perform a specific action. If the user clicks this button once, it works fine. If they double-click the button, which is allowed, we lose TempData data. We need to make sure that the TempData data is saved no matter how many times the user clicks the button. By the way, the button activates URL.Action and uses Ajax.

+3
source share
3 answers

I would suggest putting data in Session, not TempData, since TempData only stores data until the end of the next request. What happens in your situation is that the user makes a request each time he presses a button, so when you press the second button, TempData is already cleared (or will be cleared at the end of the first request).

You can disable the button after clicking it for the first time, but this may lead to a less reliable solution. Using a session and another AJAX request to clear the data in the session made when the first AJAX request was successfully returned, make sure that you know that the first AJAX request is back and the data in the session can be deleted.

+2
source

TempData.Keep ()?

+5
source

, TempData ,

TempData - /. .

If you still want to switch to TempData, make sure that all controller actions associated with it match the same TempData value again.

0
source

Source: https://habr.com/ru/post/1766341/


All Articles