我在的地方,我已經在我的控制器作了如下的查詢問題上運行:返回LINQ查詢通過視圖結果查看和循環
var query = from pmt in db.ProjectHasTags
join project in db.Projects on pmt.ProjectId equals project.ID
join tag in db.ProjectTags
on pmt.TagId equals tag.ID
group pmt by pmt.Project into pmtGroup
select new
{
Project = pmtGroup.Key,
Tags = pmtGroup.Select(project => project.ProjectTag)
};
我想把這個查詢返回到圖使用:
return View(query.ToList());
在我有以下代碼視圖文件:
@model IEnumerable<portfolio.Models.ProjectHasTag>
@foreach (var p in Model)
{
@p.Project.Title
foreach (var tag in p.Tags)
{
@tag.title
}
}
我得到以下錯誤:
The model item passed into the dictionary is of type 'System.Collections.Generic.List
1[<>f__AnonymousType6
2[portfolio.Models.Project,System.Collections.Generic.IEnumerable1[portfolio.Models.ProjectTag]]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable
1[portfolio.Models.ProjectHasTag]'.
的ProjectHasTag型號代碼:
這就是我想要達到的目標: http://i.stack.imgur.com/DAZ5n.png(我不能發表圖片還)
感謝您抽出寶貴的時間,英語不是我的第一語言。
我編輯了你的標題。請參閱:「[應該在其標題中包含」標籤「](http://meta.stackexchange.com/questions/19190/)」,其中的共識是「不,他們不應該」。 –