What is ASP.NET WebForms equivalent of ASP.NET MVC's ViewData
Wh开发者_如何学JAVAat are the conventions used in ASP.NET WebForm for passing data to view from code behind? In ASP.NET MVC for example ViewData is a key value collection or a strongly typed class object. So what do people do in case of ASP.NET WebForm.
I know we can create a property or member of a class or add stuff to Page.Items but what else besides that?
I think all the concepts of ASP.NET MVC do not map to ASP.NET Forms since they are two different paradigms of building web app.
In WebForms people mostly deal with controls and set their properties, they don't have to pass data to view as such. However if they do have to do so they use Page.Items
or HttpContext.Current.Items
or create Page properties that they access in views.
There is no direct equivalent of ViewData or ViewModel in WebForms that is used in practice. Page.Items
is the closest thing.
I'm not sure there is a direct equivalent, but the "HttpContext.Current.Items" collection can be accessed from anywhere without having to pass the context (though it does make assemblies dependent on System.Web).
You can use ViewState.
View state is a repository in an ASP.NET page that can store values that need to be retained during postback. View state is typically used for page variables that must be retained rather than user or session data. For example, you can store information in view state that will be accessed during the page load event the next time the page is sent to the server
Please see details at: https://msdn.microsoft.com/ro-ro/library/ms227551(v=vs.85).aspx
精彩评论