TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
ViewData in MVC
Prabhu Raja
Jan 31, 2014
4.5
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
About ViewData in MVC
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
Next Recommended Reading
ViewData VS ViewBag Vs TempData in MVC