I have this:
<%foreach (var item in (List<MyClass>)ViewData["something"]) {%>
and it throws exception: Unable to cast object of type ‘<>f__AnonymousType01[System.Collections.Generic.List1[MyClass]]’ to type ‘System.Collections.Generic.List`1[MyClass]’.
ViewData[“something”] contains one myClass object with four elements. How to solve this?
var xx= (from x in be.x
select x).ToList();
ViewData["something"] = new { xx };
Your problem is that you are trying to cast an anonymous object with a property which is a list to a list.
To fix it, change from
to