Difference between viewbag and viewstate?

后端 未结 3 1089
遥遥无期
遥遥无期 2020-12-30 04:38

Is there a functional difference between ViewState in Webforms and ViewBag in MVC? They seem to be the \"same thing\". And can be used in the same ways. I ask because MVC pr

3条回答
  •  自闭症患者
    2020-12-30 04:54

    Viewstate is posted back along with the content of a form to the server and thus values in it are available on post back. A viewbag only holds the values in it until the page is served then the ViewBag is removed from memory. So you can use ViewState to hold state between calls but you can not do the same with a ViewBag.

提交回复
热议问题