Reputation: 654
I read in one of the blogs as
For ViewData while enumerating type conversion is required but ViewBag since it is dynamic type conversion is not required
But we often say that ViewBag is a wrapper around ViewData, so how/why it is different when comes to type conversion ?
Upvotes: 0
Views: 207
Reputation: 14555
ViewBag is indeed a wrapper around ViewData, as you can see from the source code: https://github.com/aspnet/AspNetWebStack/blob/62d0b2df0bcca848a8e0848fd1866928df15528e/src/System.Web.Mvc/ViewPage.cs. In both cases, the value is not strongly typed, so you need to cast it before using it, unless you want to use it as an object.
Upvotes: 1