What 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?
Solution #1: ASP.NET Core Razor Pages.
Asp.Net Web Form has built-in data controls and best for rapid development with powerful data access. Asp.Net MVC is lightweight, provide full control over markup and support many features that allow fast & agile development. Hence it is best for developing an interactive web application with the latest web standards.
ViewData is a dictionary of objects that are stored and retrieved using strings as keys. It is used to transfer data from Controller to View. Since ViewData is a dictionary, it contains key-value pairs where each key must be a string. ViewData only transfers data from controller to view, not vice-versa.
To summarize, ViewBag and ViewData are used to pass the data from Controller action to View and TempData is used to pass the data from action to another action or one Controller to another Controller.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With