【发布时间】:2014-02-02 08:06:57
【问题描述】:
我陷入了困境,我试图在网上找到解决方案,但没有成功。我是使用 Entity Framework 的 MVC 新手,当我尝试运行应用程序时它抛出异常:
传入字典的模型项是类型 'System.Data.Entity.Infrastructure.DbQuery
1[<>f__AnonymousType12[UnRelatedEntity.Models.t_AbortReason,UnRelatedEntity.Models.t_Activity]]', 但是这本词典需要一个类型的模型项 'UnRelatedEntity.Models.MobilePhoneXchangeEntities1'
我使用实体作为模型,它分别从两个表中获取数据,它们之间没有关系。
控制器:
public ActionResult Index()
{
MobilePhoneXchangeEntities1 ent = new MobilePhoneXchangeEntities1();
var result = from foo in ent.t_AbortReason
from bar in ent.t_Activity
where foo.AbortReasonCategoryId != null && bar.ActivityId != null
select new { Foo = foo, Bar = bar };
return View(result);
}
查看
@model UnRelatedEntity.Models.MobilePhoneXchangeEntities1
在视图中,我只是在写上面的行,我的意思是我只是在继承模型,没有别的,但我仍然对如何键入 cast model w.r.t model 感到困惑,但我很无助。
任何人都可以在这方面为我提供帮助,但请记住,我在我的模型中使用了两个不相关的表。
【问题讨论】:
标签: c# asp.net-mvc