Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ault Nathanielsz 87 posts 407 karma points c-trib
    Aug 17, 2019 @ 10:10
    Ault Nathanielsz
    0

    Hi all,

    I am trying to iterate through the contents of a MNTP that is found in a different doctype to the one being modeled. My current code is:

        IPublishedContent varSettingsSite = Umbraco.ContentAtRoot().FirstOrDefault(x => x.ContentType.Alias == WtSettingsSite.ModelTypeAlias);
    IEnumerable<IPublishedContent> topnavLinks = varSettingsSite.Value("wtSettingsNavTop");
    if (topnavLinks != null)
    {
    <ul>
        @foreach (var item in topnavLinks)
    

    Unfortunately, I am receiving the "cannot implicitly convert type object to system.collections.generic.ienumerable

    If I just make it a var, I cannot loop through it a few lines later.

    Any thoughts?

  • Shaishav Karnani from digitallymedia.com 354 posts 1638 karma points
    Aug 17, 2019 @ 14:32
    Shaishav Karnani from digitallymedia.com
    100

    You need to use below approach to get it converted from object to IEnumerable

    var topnavLinks = varSettingsSite.Value<IEnumerable<IPublishedContent>>("wtSettingsNavTop");
    

    I hope that helps you.

    Regards,

    Shaishav

    https://www.digitallymedia.com

Please Sign in or register to post replies

Write your reply to:

Draft