我收到此错误,我不明白为什么: 传递到字典中的模型项的类型为'Devart.Data.Linq.DataQuery`1 [CHRContext.WIKIIDEE]',但此字典需要“CHRContext.WIKIREPARTO”类型的模型项。
来自模型的方法
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>
答案 0 :(得分:0)
我遇到了一个非常类似的问题,并且能够解决它。你可以在我的回答中看到如何:The model item passed into the dictionary is of type A, but this dictionary requires a model item of type B