0
我得到这个错误,我不明白为什么: 传递到字典的模型项目类型'Devart.Data.Linq.DataQuery`1 [CHRContext.WIKIIDEE]' ,但是这个词典需要一个'CHRContext.WIKIREPARTO'类型的模型项目。MVC 3模型项目传递到字典错误
从模型
public IQueryable<WIKIIDEE> GetIdeasByDeptID(int id)
{
var query = from i in db.WIKIIDEEs
where i.IDREPARTO == id
select i;
return query;
}
方法方法从控制器
public ActionResult List(int id)
{
try
{
IdeeRepository ideeRepo = new IdeeRepository();
IQueryable<WIKIIDEE> list = ideeRepo.GetIdeasByDeptID(id);
return View(list);
}
catch (Exception Ex)
{
return View("Error");
}
}
,并查看
@model IEnumerable<CHRContext.WIKIIDEE>
@{
ViewBag.Title = "List";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>List</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
IDREPARTO
</th>
<th>
DATAINSERIMENTO
</th>
<th>
DESCRIZIONE
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.IDREPARTO)
</td>
<td>
@Html.DisplayFor(modelItem => item.DATAINSERIMENTO)
</td>
<td>
@Html.DisplayFor(modelItem => item.DESCRIZIONE)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
</td>
</tr>
}
</table>
你在哪一行得到错误?在控制器中? – 2012-01-10 15:13:02
当视图中的foreach完成了元素的迭代 – Alex 2012-01-10 15:18:42