What is ASP.NET WebForms equivalent to ASP.NET MVC ViewData

What are the conventions used in ASP.NET WebForm to pass data for viewing from code? In ASP.NET MVC, for example, ViewData is a key collection of values ​​or a strongly typed class object. So what are people doing in the case of ASP.NET WebForm.

I know that we can create a property or a member of a class or add material to Page.Items, but what else is there?

+6
source share
3 answers

I think that all ASP.NET MVC concepts do not map to ASP.NET forms, because they are two different paradigms for building a web application.

In WebForms, people mostly deal with controls and set their properties; they do not need to pass data for viewing as such. However, if they need it, they use Page.Items or HttpContext.Current.Items or create the page properties that they access in views.

There is no direct equivalent to ViewData or ViewModel in WebForms, which is used in practice. Page.Items are the closest thing.

+7
source

I'm not sure there is a direct equivalent, but the "HttpContext.Current.Items" collection can be accessed from anywhere without having to pass a context (although it makes assemblies dependent on System.Web).

+3
source

You can use ViewState.

View state is a repository on an ASP.NET page that can store values ​​that need to be preserved during postback. View state is typically used for page variables that need to be saved, and not for user or session data. For example, you can store information in a viewing state, which will be available during the page load event the next time the page is sent to the server.

For more details see: https://msdn.microsoft.com/ro-ro/library/ms227551(v=vs.85).aspx

0
source

Source: https://habr.com/ru/post/891439/


All Articles