I have seen many questions about this, but I have never had the answer I need.
I am converting a rather large web application from Web Forms to MVC, and after a while I ran into the problem of transferring data to a view. In action, I execute the code:
//This is just an example ViewData["QProducts"] = from p in db.Products select new{Name = p.Name, Date = p.ToShortDateString() } ViewData["QUsers"] = from u in db.Users select u;
I use a foreach loop to iterate over objects in html, for example:
foreach(var q in (IEnumerable)ViewData["QEvents"]) { }
Before using MVC, I just used asp:Repeater , but since it is MVC, I cannot use ASP.NET controls.
How should I pass this data to a view? I really have no way of not using Anonymous types here. <%#ViewData.Eval()%> will obviously not work.
Any ideas?
linq anonymous-types asp.net-mvc
impClaw
source share