Is it possible in MVC3 (Razor if possible) to have a page rendered with totals and subtotals?
e.g.
I have 5,000 rows in my db table retreived through EF4/L2E.
Type Category Product Month1 Month2 Month3
_______________________________________________________________
Foo Large Big Foo 64 32 16
Foo Large Massive Foo 18 9 4
Foo Small Foolet 120 110 120
Foo Small Fooling 200 210 220
Foo Medium Standard Foo 100 100 100
Bob Small Bobbling 6 5 4
Bob Medium Bobble 8 6 4
Is it possible to get a page to render:
Type Category Month1 Month2...
Foo 502 461
Large 82 41
Small 320 320
Medium 100 100
Bob 14 11
Small 6 5
Medium 8 6
Do I need to create a set of view models, one for Type, one for Category etc?
I’ve looked at page layouts, but they don’t seem to be what I need?
You can achieve this with MVC WebGrid by nesting two webgrids.
Razor Nested WebGrid
You can have single ViewModel containing instance of Type and Category model.
To show the Total in both webgrids, use LINQ. Get the Sum for each Category and Type in TypeModel and CategoryModel.
Check the “Sum -Grouped” example in following link.
http://msdn.microsoft.com/en-us/vcsharp/aa336747