有人能告诉我为什么这个 ViewBag 不想呈现它的值吗?
ViewBag.fields = from f in db.Fields
where f.FieldId == id
select new { name = f.Name, id = f.FieldId };
@foreach(var item in ViewBag.fields)
{
@item.name//error, cannot find the definition of name
}
我也试过这个。
@foreach(var item in ViewBag.fields)
{
@item[0]//error, 'object' does not contain a definition for 'name'
}
但是,如果这样做
@foreach(var item in ViewBag.fields)
{
@item
}
它呈现
{name = Document, id=1}
我需要做什么?