New to MVC and Linq.
I'm was able to display all records just fine but now I was trying to get a count of records by name and just select 2 fields:Name and Count
I thought I should create a new ViewModel, fill the Name,Count and send it to the view.
public ActionResult Index()
{
var load =
db.loadingPPHs.Where(s => s.WORKDAY == db.loadingPPHs.Max(x => x.WORKDAY))
.GroupBy(fu => fu.TMNAME)
.Select(g => new {Name = g.Key, Count = g.Count()}).ToList();
var viewModel = new loadingViewModel
{
LoadingListCount = load
};
return View(viewModel);
}
The linq above works as expected. ViewModel:
public class loadingViewModel
{
public IEnumerable<LoadingListCount> LoadingListCount { get; set; }
}
public class LoadingListCount
{
public string Name{ get; set; }
public int Count { get; set; }
}
However, I'm getting an error. Cannot implicitly convert type 'System.Collections.Generic.List<>' to 'System.Collections.Generic.IEnumerable'. An explicit conversion exists (are you missing a cast?)
I have trying converting the query to list and to IEnumerable but no luck. I've searched around other posts but I have not have luck with them.