UPDATE: See "Use AB_SocialMetaModel in CMS website to generate all social media meta/link/script markup" for simplifying wrapper class.

Most MVC websites need to output some link tags on each page, usually in ~/Views/Shared/_Layout.cshtml or a partial template. Accelerator 6.4.1 introduces some helper classes to create strongly-typed model objects that represent these tags, and to render them consistently.

See also: AB_PageMetaInfoModel for meta tag markup

See also: AB_PageScriptInfoModel for script tag markup and Json-LD

AB_PageLinkEntity supports all of the standard HTML5 attributes for link elements. Only Href is required; if it is empty the link element will not be rendered.

@using A4DN.Core.MVC.CMS.Models
@{
    var linkModel = new AB_PageLinkInfoModel();

    linkModel.AddRange(new List<AB_PageLinkEntity>
    {
        new AB_PageLinkEntity { Rel = "canonical", Href = Request.Url.AbsoluteUri },
        new AB_PageLinkEntity { Rel = "icon", Sizes = "32x32", Type = "image/png", Href = Url.Content("~/favicon.png") },
        new AB_PageLinkEntity { Rel = "shortcut icon", Type = "image/x-icon", Href = Url.Content("~/favicon.ico") },
        // new AB_PageLinkEntity { Rel = "apple-touch-startup-image", Href = Url.am_MediaFile("apple-touch-startup.png") },
        new AB_PageLinkEntity { Rel = "apple-touch-icon", Href = Url.Content("~/apple-touch-icon-iphone.png") },
        new AB_PageLinkEntity { Rel = "apple-touch-icon", Sizes = "76x76", Href = Url.Content("~/apple-touch-icon-ipad.png") },
        new AB_PageLinkEntity { Rel = "apple-touch-icon", Sizes = "120x120", Href = Url.Content("~/apple-touch-icon-iphone-retina.png") },
        new AB_PageLinkEntity { Rel = "apple-touch-icon", Sizes = "152x152", Href = Url.Content("~/apple-touch-icon-ipad-retina.png") },
    });
}
@Html.DisplayFor(m => linkModel)

To render the model, ~/Views/Shared/DisplayTemplates/AB_PageLinkInfoModel.cshtml is required:

@model A4DN.Core.MVC.CMS.Models.AB_PageLinkInfoModel
@foreach (var entity in Model.Where(m => !String.IsNullOrWhiteSpace(m.Href)))
{
<link rel="@entity.Rel" href="@entity.Href" crossorigin="@entity.CrossOrigin" hreflang="@entity.HrefLang" media="@entity.Media" sizes="@entity.Sizes" title="@entity.Title" type="@entity.Type">
}