Umbraco 7 Tag and Sorting Tags in to Alphabetical Order Using a Dictionary

Umbraco 7 Tag and Sorting Tags in to Alphabetical Order Using a Dictionary:

<ul>
@{
    Dictionary<string, int> tagsList =
            new Dictionary<string, int>();
}
 @foreach (var c in CurrentPage.Children())
    {
        if(c.HasValue("tags"))
        {
       
           foreach (var item in c.GetPropertyValue<string[]>("tags"))
           {
                if (!tagsList.ContainsKey(item))
                {          
                    tagsList.Add("" + item, 1);
                    <!--<p>@item</p>-->
                }
           }
         
        }
   
    }
    @{
     var ordered = tagsList.OrderBy(x => x.Key);
              
                foreach(var i in ordered)
                {
                 <li class="filterLink"><a href="@i.Key">@i.Key</a></li>
                }
                <!--<li class="filterLink"><a href="">item</a></li>-->
    }
</ul>

Comments

Popular posts from this blog

Umbraco 7 - C# Razor - Passing a parameter variable from a Template to a Partial View.

Umbraco Razor Sort Nodes Ascending or Descending

Umbraco - Reset the Admin Password via SQL Server