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 35 posts 149 karma points
    29 days ago
    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 257 posts 1119 karma points
    29 days ago
    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