currently i have following linq
ViewBag.Products = db.Transaction.GroupBy(n => n.ProductName,
(key, values) => new { ProductName = key, Count = values.Count() });
in view i need to get the list of each product and its count
but in view i get the query printed
if i use productid i get productid count
i want to group by productid but name and count shld be displayed
requirement
product1 20
product2 18
product3 4
Sunil Singh
28-May-2017Hi manish
According to your description I have used the following Linq statement and it works well.
viewbag will convert anonymous type to object type,so I convert it to Json type and it will be better to show in the view
ViewBag.productTest = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(products));
Your view code is
Hope it helps you