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
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Difference Between ViewBag & ViewData in MVC
WhatsApp
Yogesh Bajpai
Apr 02
21.3
k
0
0
25
Blog
ViewBag vs ViewData
ViewData is a dictionary of objects that is derived from the ViewDataDictionary class and accessible using strings as keys.
ViewBag is a dynamic property that takes advantage of the new dynamic features in C# 4.0.
ViewData requires typecasting for complex data types and checks for null values to avoid errors.
ViewBag doesn't require typecasting for complex data types.
Calling of ViewBag is
ViewBag.Name = "Yogesh";
Calling of ViewData is
ViewData["Name"] = "yogesh";
ViewBag
ViewData
MVC
ASP.NET
ASP.NET MVC
Up Next
ViewData VS ViewBag Vs TempData in MVC
Ebook Download
View all
Hands on ASP.NET GridView
Read by 16.9k people
Download Now!
Learn
View all
Membership not found