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

Create a .NET Contact Form that Gets the Last Url Visited in C# Can also be Used in Umbraco

Umbraco - Reset the Admin Password via SQL Server

Umbraco Macro for IFrame when Embedding Video, Vimeo Universal Player, or other types of IFrame on to a Page XSLT version and Razor Version