Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
ViewBag.LogoFileId = new SelectList(db.Files, "FileId", "FileId", chain.LogoFileId);
ViewBag.LangId = langId;
ViewData["catid"] = catid;
ViewData["languages"] = db.Languages.OrderBy(l => l.LanguageId).ToList();
Posted

ViewData acts like a collection you add things to, whereas ViewBag is a dynamic type so you simply set and read properties on it. ViewData was conceived before dynamic types were implemented so it was a way of holding a collection of objects you could define at run-time.
 
Share this answer
 
Comments
Member 11919288 7-Sep-15 3:04am    
What is the difference in use?
How should use any kind?
F-ES Sitecore 7-Sep-15 4:17am    
The only real difference is the syntax. ViewBag is the latest version and has, in a way, superseded ViewData as it uses technology that wasn't around when ViewData was implemented. Just use whichever looks\feels better to you, and whichever you prefer.
Hello,
One of the best articles you can refer for this and better understanding:
ViewBag Vs ViewData Vs TempData Vs Session[^]

Hope this clears your concept here.
Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900