user6950100 user6950100 - 5 months ago 21
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?


simple, use a foreach loop:

@foreach(var item in Model.ListOfItems)
    <li><a href="@Html.DisplayFor(m => item)">Some text</a></li>