I´m writing an ASP .NET MVC web site and i´m with a LINQ problem. I have a simple class
public class Tag
{
public int TagId { get; set; }
public string Nome { get; set; }
... [other props]....
}
And i want to pass to the view a list of grouped Nomes. I tried to the following LINQ code to generate a list
var teste = (from t in db.Tags
group t by t.Nome into g
select new
{
Nome = g.Key
}).ToList();
ViewBag.ListaTags = teste;
and it´s ok, but if i use the following code in the View
@foreach (var item in ViewBag.ListaTags)
{
@item.Nome
}
I got an error message saying that the object item has no Nome property. If i try @item instead of @item.Nome, it display {Nome = "Test"}. It´s like I have an object but I can´t access it´s properties.