Looks like your building a collection of Anonymous object. What you should do is, Create a ViewModel and use that in your LINQ query by updating the projection part. So that instead returning a list of anonymous items, it returns a list of your viewmodel class instances
public class StockDetail
{
public string CategoryName { set;get;}
public int TotalItems { set;get;}
}
Now in your GET action method, update the projection part of the LINQ expression and load the result into a list of StockDetail
public ActionResult GetCategories()
{
List<ProfitsModel> prof =GetCollectionOfProfitsModelFromSomewhere();
var items= from p in prof
group p by p.IdCategory.Name into g select new StockDetail
{ Category = g.Key, TotalUnitsInStock = g.Sum(p => p.Value) };
return View(items);
}
Make your view strongly typed to a collection of StockDetails
@model List<StockDetail>
@foreach(item in Model)
{
<p>@item.Category </p>
<p>@item.TotalUnitsInStock.ToString()</p>
}