Tempdata, viewdata, viewbag

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.