In my controller I use the following:
ViewBag.ReferenceId = new SelectList(_reference.Get("00")
.AsEnumerable()
.OrderBy(o => o.Order), "RowKey", "Value", "00");
Then in my view I use the following extension to create a dropdown:
@Html.DropDownList("ReferenceID",
null,
new {
id = "ReferenceID",
@class = "combobox2",
style="width: 150px;"
}
)
Now I would like to change this to create an unordered list. Something like the following:
<ul id="categories" class="pane list">
<li><a href="#">Websites</a></li>
<li><a href="#">Web Design</a></li>
<li><a href="#">Print</a></li>
</ul>
Is there any MVC extension that can do this for me or is there an easy way I can code something?
There is no equivalent, though you could write it on your own like this:
tagsList = "<ul>{0}</ul>";
tagsListItem = "<li>{0}</li>";
StringBuilder result = new StringBuilder();
list.ForEach(listItem => result.AppendFormat(tagsListItem, item.ToString()));
return string.Format(tagsList, result.ToString());
And you could fit the code for your needs (like adding additional tags, attributes etc.)
Write your HtmlHelper http://www.asp.net/mvc/tutorials/older-versions/views/creating-custom-html-helpers-cs but the best ways is to browse MVC source code and learn http://aspnet.codeplex.com/SourceControl/changeset/view/72551#288014 or use a foreach.
<ul id="categories" class="pane list">
@foreach(var category in categories)
{
<li><a href="#">@category</a></li>
}
</ul>
Regards