user6950100 user6950100 - 1 year ago 92
HTML Question

How to use DisplayFor to display a list of hrefs

I have an MVC project that has a list of items. I use

@Html.DisplayFor(m => m.ListOfItems)

when running, this shows the list of items. In the markup, it is displayed like this:


But I want them in an
so that I can make them hrefs. How do I do this?

Answer Source

simple, use a foreach loop:

@foreach(var item in Model.ListOfItems)
    <li><a href="@Html.DisplayFor(m => item)">Some text</a></li>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download