MissioDei
MissioDei

Reputation: 809

MVC List of links

I'm capturing an external URL (string) in a form.

I want to pass this string to a view but transform it into a clickable link.

Currently I'm using this in the view which of course is just going to display my string. How do I turn it into a link?

  @Html.DisplayFor(modelItem => item.Website)

Thanks.

Upvotes: 1

Views: 1888

Answers (1)

Jamie Dixon
Jamie Dixon

Reputation: 53991

You can simply do:

<a href="@Model.Website">@Model.Website</a>

or for a list of urls:

@foreach(var url in Model.Websites)
{
     <a href="@url">@url</a>
}

Upvotes: 2

Related Questions