1. viewdata and viewbag
The life cycle of viewbag and viewdata is the same and only valid for the current view. The difference is that viewbag is no longer a dictionary key-Value Pair structure, but a dynamic type.
2. tempdata
Tempdata is stored in the session. When the Controller executes a request, it first obtains tempdata from the session, then clears the session, and obtains tempdata. Although it is saved in an internal dictionary object, however, each entry in the set is deleted from the dictionary table once accessed.
DetailsCodeAt the level, the tempdata acquisition process reads data from the session of controllercontext through the sessionstatetempdataprovider. loadtempdata method, and then clears the session. Therefore, tempdata can only be transmitted once across the controller.
If you want to read the value of tempdata without deleting it, you can use the tempdata. Peek ("key") method. If you want to keep the value in tempdata again, you can use tempdata. Keep ("key ").