var s = myInventoryEntities.p_Forms().Select(i => new { i.Customer, i.Order_ID }).Distinct().ToList();
ViewBag.MyData = s;
return View();
this gives me
{ Customer = "Bob", Order_ID = 2644550 }
In my razor code
i traverse the data
@foreach ( var x in @ViewBag.MyData){
x.Customer // Does not exist! :(
}
Please help!
‘object’ does not contain a definition for ‘Customer’
ViewBag data’s life time is very limited. Are you sure you are coming to this view from the same action method where you set the ViewBag data ?
Suggestion : Try to Avoid Dynamic types liek ViewData/ViewBag. Sticking to Strongly typed makes your code much better readable/ maintainable.
If your Domain object and What you want to display is same, do not bother about creating a ViewModel. else create a viewmodel
and return that instead of the ViewBag
And in the view