Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
ViewData in MVC
WhatsApp
Prabhu Raja
11y
4.6
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
Up Next
ViewData VS ViewBag Vs TempData in MVC
Ebook Download
View all
ASP.NET MVC 5: A Beginner’s Guide
Read by 28.1k people
Download Now!
Learn
View all
Membership not found