Filtering Taxonmomy Terms in Shape Alternate

Topics: Customizing Orchard
Feb 28 at 9:43 AM
Hi There
I am pulling a ContentItems from a projection into a custom shape.

See below
@{
    var items = Model.ContentItems;
}

        <ul>
        @foreach (var item in items)
        {
            var terms = item.Leads.Area.Terms;
            
             foreach (var term in terms) {
                 
                  <li>@term.Name</li>
             }
        }

        </ul>
The terms are pulling through correctly but my problem is that some of the terms are duplicated and not in Alphabetical order

IE

Cape Town
Joburg
Joburg
Cape Town
Durban

I would like to know how to edit the query in the view so that the results will come out like this.

Cape Town
Durban
Joburg

Thanks
Stanton
Feb 28 at 10:07 AM
You can put the names into a List before displaying and enumarate on list.Distinct().OrderBy(x=>x) to create html tags.


Marked as answer by Stanton_R on 2/28/2014 at 2:43 AM
Feb 28 at 10:42 AM
Cool Shot for that.
For interest sake here is my code.
@{
    var items = Model.ContentItems;
    var list = new List<dynamic>();

    foreach (var item in items)
    {
        var terms = item.Leads.Area.Terms;

        foreach (var term in terms)
        {
            list.Add(term);
        }
    }
    IEnumerable<dynamic> filtered = list.Distinct().OrderBy(x => x.Name);
}

<ul>
    @foreach (var item in filtered)
    {
        <li>@item.Id - @item.Name</li>
    }
</ul>