【发布时间】:2014-01-12 07:42:23
【问题描述】:
我在从 ASP.net MVC 实体框架中的两个表加入后检索数据,但在视图内部无法访问属性,当我运行代码时出现错误:传递到字典中的模型项的类型为“System.Collections” .Generic.List1[<>f__AnonymousType16.....
但是这本词典....System.Collections.Generic.IEnumerable`1。谢谢你的回答。。
我的代码是:
家庭控制器:
dbEntities dbquery = new dbEntities();
public ActionResult Index()
{
var id = 1;
var query = (from x in dbquery.Emp_
join y in dbquery.Departments on x.Id equals y.emp_id
where x.Id == id
select new { x.Id, x.EmployeeName, x.Department, y.emp_id, y.Dept_Id, y.DeptName }).ToList();
return View(query.ToList());
}
在视图中:
@model IEnumerable
@foreach (var item in Model)
{
@item.... (Properties are inaccessible)
}
【问题讨论】:
标签: c# asp.net asp.net-mvc asp.net-mvc-3 asp.net-mvc-4