Search code examples
linqentity-frameworkasp.net-mvc-4webgrid

Cannot implicitly convert type System.Collections.Generic.List<>' to 'System.Collections.Generic.List<>


I am new to MVC4, I want to implement WebGrid, When retrieving data for model.activity its working fine. For clarification i am combining two tables to get data.

Here its showing error like this Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.Generic.List

Please help me to solve this problem. thanks in advance

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; }
}

I am adding data to the model to display in 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);

Solution

  • MyViewModel has the wrong type for the clarification field...

    try the following instead

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