【发布时间】:2015-01-05 10:13:15
【问题描述】:
我是 MVC4 的新手,我想实现 WebGrid,在为 model.activity 检索数据时,它工作正常。为了澄清起见,我正在组合两个表来获取数据。
这里显示的错误是这样的 无法将类型“System.Collections.Generic.List”隐式转换为“System.Collections.Generic.List”
请帮我解决这个问题。提前致谢
public class MyViewModel
{
public List<Tbl_Activity> activity;
public List<Tbl_Clarification> clarification;
}
public class ClarificationEntities
{
public int ClrNo { get; set; }
public Nullable<int> DailyReportID { get; set; }
public string ReportingMgrComment { get; set; }
public Nullable<System.DateTime> CreatedOn { get; set; }
public string StaffComment { get; set; }
public Nullable<int> CreatedBy { get; set; }
public string Name { get; set; }
}
我正在向模型中添加数据以在 WebGrid 中显示
MyViewModel model = new MyViewModel();
model.activity = db.Tbl_Activity.Where(x => x.DailyReportID == driD).ToList();
model.clarification = (from c in db.Tbl_Clarification
join u in db.Tbl_Users on c.CreatedBy equals u.CreatedBy
where c.DailyReportID == did
select new ClarificationEntities
{
ClrNo = c.ClrNo,
ReportingMgrComment = c.ReportingMgrComment,
StaffComment = c.StaffComment,
DailyReportID=c.DailyReportID,
Name=u.Name
}).ToList();
return View(model);
【问题讨论】:
-
您的
model.clarification是List<Tbl_Clarification>类型,但您正在获取List<ClarificationEntities>
标签: linq entity-framework asp.net-mvc-4 webgrid