4
  • I am using DXA 1.7.
  • I have a schema with a component link field called navigationSet.
  • navigationSet is multivalue field
  • navigationSet links to only a LinkList

My footerNavigation model looks something like this:

public class GlobalFooterNavigation : EntityModel
{
    [SemanticProperty("c:navigationSet")]
    public List<Link> NavigationSets { get; set; }

}

I've created the NavigationSets model to look like this, which essentially a duplicate of LinkList

[Serializable]
public class NavigationSet<T> : EntityModel
{
    public string Headline { get; set; }
    public List<T> Links { get; set; }
    public NavigationSet()
    {
        Links = new List<T>();
    }
}

Unfortunately, I still cannot access the Headline inside of my template:

@model GlobalFooterNavigation

<div class="footer-navigation">
    <div class="footer-panel">
        @if (Model.NavigationSets != null)
        {
            foreach (var navigationSet in Model.NavigationSets)
            {

                <div class="footer-panel-inner">
                    <h3>@navigationSet.Headline</h3> <!--comes up empty -->
                    <ul>
                        <li><a href="#">Contact company</a></li>    
                    </ul>
                </div>
            }
        }

am I making a mistake in the model, the template, or both?

3

I was mostly making a mistake in my initial model for my component

    public class GlobalFooterNavigation : EntityModel
    {

    [SemanticProperty("c:navigationSet")]
    public List<NavigationSet> NavigationSets { get; set; }

    }

I wanted my NavigationSet to be a list. I was a copy-pasta of LinkList, but I found that I could simplify it a bit. Since I limited the schema field to only be able to link to LinkList components, I don't have to have a generic type.

[Serializable]
public class NavigationSet : EntityModel
{
    public string Headline { get; set; }
    public List<Link> Links { get; set; }
}

This pattern would work any time I have a multivalue component link field, but it's a component link field for exactly one type of component.

This now enables the following, in the template:

<div class="footer-panel desktop-only">
    @if (Model.NavigationSets != null)
    {
        foreach (var navSet in Model.NavigationSets)
        {

            <div class="footer-panel-inner">

                <h3>@(navSet != null ? navSet.Headline: String.Empty)</h3>
                <ul>
                    @foreach(var navLink in navSet.Links)
                    {
                        <li>
                            <a href="@navLink.Url">@navLink.LinkText</a>
                        </li>
                    }
                </ul>
            </div>
        }
    }
</div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.