Documentation Center

Public Semantics (.NET)

You can also use the same View Model semantics to make the content machine readable.

For example, if you wanted to use the Schema.org vocabulary to annotate rendered content, add the following code to the View Model:

using System;
using Sdl.Web.Common.Models;

namespace Example.Models
{
    [SemanticEntity(Vocab = "http://Schema.org", EntityName = "Offer", Prefix = "s", Public = true)]
    public class SpecialOffer : EntityModel
    {
        [SemanticProperty("s:name")]
        public string Headline { get; set; }
        [SemanticProperty("s:image")]
        public Image Image { get; set; }
        [SemanticProperty("s:description")]
        public string Description { get; set; }
        [SemanticProperty("s:url")]
        public string Link { get; set; }
        [SemanticProperty("s:validThrough")]
        public DateTime? ExpiryDate { get; set; }
    }
}

Note the Public = true part of the SemanticEntity attribute indicates that you want to write the semantics out when rendering content.

If used in combination with the @Html.DxaEntityMarkup() and @Html.DxaPropertyMarkup()methods in your Views, the following semantics end up in your rendered output:

<div class="container-fluid" prefix="s: http://Schema.org" typeof="s:Offer">
    <div id="location-tile" class="row">
        <div class="col-sm-6" property="s:image">
            <img alt="Balloons" src="/media/balloons.jpg" width="100%">
        </div>
        <div class="col-sm-6">
            <div class="tile">
                <h1 property="s:name">Win a holiday to Brazil!</h1>
                <p property="s:description">Enter this competition to win a once in a lifetime trip to Brazil!</p>
                <a class="btn btn-primary" property="s:url" href="/offers/win-brazil-holiday">More info</a>
                <br>
                <p class="meta small">Valid until <span property="s:validThrough">Wednesday, July 9, 2016</span></p>
            </div>
        </div>
    </div>
</div>