Tempdata viewdata viewbag can be used to save data. The differences between them are as follows:
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.
The life cycle of viewdata is the same as that of the view, which is only valid for the current view.
The life cycle of viewbag and viewdata is the same, but the former view is valid. The difference is that the viewbag type is not the dictionary key-Value Pair structure, but the dynamic type, added in mvc3.