Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the data transfer method from controller to view in Asp.Net

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the knowledge of "what is the method of data transmission from controller to view in Asp.Net". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

In the process of MVC programming, it is inevitable to exchange data between front-end and back-end. Three ways are provided in C #, as follows:

1] ViewData object

ViewData is a dictionary collection data, which is an attribute of "View Base Class" and "Controller Base Class".

The common usage is to write data in the controller and read the data in the view

The Value of ViewData can store data of any data type, so forced type conversion is required in the process of use.

2] dynamic object ViewBag

ViewBag is an object of type dynamic, and it is also an attribute of "View Base Class" and "Controller Base Class"

Benefits: very flexible

Features: ViewBag is actually the packaging of ViewData data. Data saved with ViewData can be read by ViewBag, and vice versa. ViewBag is recommended in the general development process.

3] transfer TempData across request data

Temp Data is a dictionary object and can also be used for data transfer from controller to view, similar to ViewData

Features: Temp Data also enables data transfer between different requests

Note:

The Temp Data data saving mechanism is Session, but it is different from Session.

Case 1. After TempData saves the data, if it is used, it will be cleared, so subsequent requests will not be used again.

Case 2. After TempData saves the data, if it is not used, it saves the life cycle of the session.

This is the end of the content of "what is the method of data transfer from controller to view in Asp.Net". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report