I would like to render a list of HTML links in ASP.NET MVC. Note that the links are absolute and external to the website being designed. The following code
Orchard project has an HtmlHelper extensions class which has a link builder method.
See: HtmlHelperExtensions.Link()
http://orchard.codeplex.com/SourceControl/changeset/view/dbec3d05e6d1#src%2fOrchard%2fMvc%2fHtml%2fHtmlHelperExtensions.cs
Allows the following usage:
- @Html.Link(Model.Path, Model.Title)
Update The above link is no longer valid, but if you download the source, you will find HtmlHelperExtensions which has 5 overloads for Links, one of which looks like this:
public static IHtmlString Link(this HtmlHelper htmlHelper, string linkContents, string href, IDictionary htmlAttributes) {
var tagBuilder = new TagBuilder("a") { InnerHtml = htmlHelper.Encode(linkContents) };
tagBuilder.MergeAttributes(htmlAttributes);
tagBuilder.MergeAttribute("href", href);
return new HtmlString(tagBuilder.ToString(TagRenderMode.Normal));
}