【问题标题】:Cannot implicitly convert type System.Collections.Generic.List<>' to 'System.Collections.Generic.List<>无法将类型 System.Collections.Generic.List<>' 隐式转换为 'System.Collections.Generic.List<>
【发布时间】: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.clarificationList&lt;Tbl_Clarification&gt; 类型,但您正在获取 List&lt;ClarificationEntities&gt;

标签: linq entity-framework asp.net-mvc-4 webgrid


【解决方案1】:

MyViewModelclarification 字段类型错误...

改用以下方法

public class MyViewModel
{
    public List<Tbl_Activity> activity;
    public List<ClarificationEntities> clarification;
}

【讨论】:

    猜你喜欢
    • 2021-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-08
    • 2019-01-03
    • 1970-01-01
    • 2020-06-16
    相关资源
    最近更新 更多