我是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);
答案 0 :(得分:2)
MyViewModel
的{{1}}字段类型错误...
尝试以下代替
clarification