Skip to content

Instantly share code, notes, and snippets.

@csharpforevermore
Created November 19, 2013 12:16
Show Gist options
  • Save csharpforevermore/7544504 to your computer and use it in GitHub Desktop.
Save csharpforevermore/7544504 to your computer and use it in GitHub Desktop.
Output a list of strings as an ordered list of HTML e.g. <ol> <li> ... </li><li>...</li></ol>
public static HtmlString OrderedList(IEnumerable<string> items)
{
var sb = new StringBuilder();
var orderedList = new TagBuilder("ol");
foreach (var item in items)
{
var listItem = new TagBuilder("li");
listItem.SetInnerText(item);
sb.AppendLine(listItem.ToString(TagRenderMode.Normal));
}
orderedList.InnerHtml = sb.ToString();
return new HtmlString(orderedList.ToString(TagRenderMode.Normal));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment