C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
ViewData in MVC
WhatsApp
Prabhu Raja
11y
4.7
k
0
0
25
Blog
ViewData in MVC is a public dictionary object, which is used to pass data from controller’s action to corresponding view. This object is derived from ViewDataDictionary class.
The data stored in this object will be available during the current request only. And this object will be set to null, when redirection occurs. So we can’t retrieve the data stored in this object after redirection.
This object is like a temporary session variable but its life time is very short. As I told earlier, the life of this object will end, when redirection happens.
And type casting is required, when we use this object for data in complex data type and check for null before use is the best practice to avoid errors like “object reference not set to an instance of an object”.
For more detail and source code,
ViewData in MVC
.
ViewData in MVC
People also reading
Membership not found