I am not sure if I understood your requirement completely however I think you are trying to perform some aggregates on the data you have received on the client side. If that is the case you can use
Its pretty awesome and gives you the ability to use .Net methods at client side code.
Another way is, define a ViewModel and add QtySum and LineCount property. Compute that at server side code and return the ViewModel to client. Client side code will use these values to render UI.
Update 1:
Looking at more information on what you want to achieve I am sure you definitely want to go with defining ViewModel approach. I prefer that as it give me more control as I am writing server side code and has all the abilities (.net methods). Second I prefer to keep view as dumb and lightweight as possible.
In you current scenario, I would define view model as below (consider this example for guidance and modify as per your need):
public class PickingListViewModel
{
public int Id { get; set; }
public int TransID { get; set; }
public PickingListSkuViewModel SkuGroupModel { get; set; }
}
public class PickingListSkuViewModel
{
public string SKU { get; set; }
public IEnumerable<PickingListItemViewModel> GroupItems { get; set; }
}
public class PickingListItemViewModel
{
public int ColorId { get; set; }
public string Color { get; set; }
public double Qty { get; set; }
public decimal Price { get; set; }
}
Now at controller I can fill the view model like so (again note that preferred approach is to fetch the data from business or data layer):
public ActionResult Index()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
// Read this data from business layer
var group1 = new PickingListSkuViewModel
{
SKU = "61009",
GroupItems = new List<PickingListItemViewModel>
{
new PickingListItemViewModel
{
Color = "Blue",
Qty = 12,
Price = (decimal) 2.5
},
new PickingListItemViewModel
{
Color = "Red",
Qty = 3,
Price = (decimal) 4.5
}
,
new PickingListItemViewModel
{
Color = "Green",
Qty = 4,
Price = (decimal) 1.5
}
}
};
var group2 = new PickingListSkuViewModel
{
SKU = "61011",
GroupItems = new List<PickingListItemViewModel>
{
new PickingListItemViewModel
{
Color = "Blue",
Qty = 12,
Price = (decimal) 2.5
},
new PickingListItemViewModel
{
Color = "Red",
Qty = 3,
Price = (decimal) 4.5
}
,
new PickingListItemViewModel
{
Color = "Green",
Qty = 4,
Price = (decimal) 1.5
}
}
};
var model = new List<PickingListViewModel>
{
new PickingListViewModel
{
Id = 1,
TransID = 101,
SkuGroupModel = group1
},
new PickingListViewModel
{
Id = 2,
TransID = 102,
SkuGroupModel = group2
}
};
return View(model);
}
Controller should just initialize the model and return it to appropriate view.
I have not included view code as I believe you are comfortable with it. As hint you now have all the information per group, just write rendering code. You can add sum or count or any other aggregate into PickingListItemViewModel
or simple computation can be performed on view code e.g. TotalPrice = Quantity * Price
Let me know if you have any follow up question. Hope this helps.