public ActionResult Index()
{
var groups = db.SHP_Products
.GroupBy(c => c.SHP_Category.Name,
(category, items) => new
{
CategoryName = category,
ItemCount = items.Count(),
Items = items
}
);
ViewBag.group = groups.ToList();
return View();
}
When running this it will show an error like this:
<ul>
@foreach (var m in ViewBag.group)
{
<h2>@m.CategoryName</h2>
<a href="#" class="prev1">Previous</a><a href="#" class="next1">Next</a>
<li></li>
}
</ul>
'object' does not contain a definition for 'CategoryName'