0

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?

BlueChippy
  • 5,935
  • 16
  • 81
  • 131

2 Answers2

1

Try Telerik MVC Grid. It has many features and also inbuilt with your requirements

http://demos.telerik.com/aspnet-mvc/grid/aggregatesajax

getmk
  • 155
  • 3
  • 13
0

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

Community
  • 1
  • 1
kaps
  • 468
  • 4
  • 18
  • How do I get the totals in here? – BlueChippy Sep 06 '11 at 07:40
  • Total you will have to get into Type and Category Models. Use LINQ to get the Total. – kaps Sep 07 '11 at 15:18
  • I think this is the way I will go because it gives me a lot more control over the totalling and grouping than the Telerik Grid. I can just write ViewModels and nest them in IEnumerable where necessary – BlueChippy Sep 08 '11 at 10:04