I'm having a bit of trouble figuring this out. I have a list of objects with two properties: Alias
and Value
I need to show a list of these objects where the Alias
property is grouped by the Value
string value. Like this:
MyAlias1, MyAlias2, MyAlias3
- Value string which is the same for above three aliases
MyAlias4, MyAlias5
- Value string which is the same for above three aliases
What I have so far is:
var groups = lst.GroupBy(x => new { x.Alias, x.Value });
foreach(var group in groups)
{
@group.Value
}
But I'm not sure what to do from there, to actually show them as grouped items.
Any help is greatly appreciated!
Here is grouping
Here is displaying
BTW it's better to create ViewModels in controller, then doing Linq in view:
In controller:
I think you need to group by the value, then for each group you can print out what you need: