Copied to clipboard

Flag this post as spam?

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


  • Alessandro 21 posts 51 karma points
    Dec 02, 2013 @ 12:50
    Alessandro
    0

    Multinode treepicker strange behaviour Umbraco 7

    Hi

    on an umbraco7 site i have a document type (say "news") with a property (say "banner") of "MultiNode TreePicker"

    In a partial view (/view/partial) that inherits from Umbraco.Web.Mvc.UmbracoTemplatePage i have the following code snippet:

    @CurrentPage.banner.GetType() @CurrentPage.banner
    

    and this is the output:

    • Umbraco.Core.Dynamics.DynamicNull

    • System.Int32 1104

    • System.String 1104,1108

    So i cant use the same foreach code to retrive the id of the single item because CurrentPage.alias returns an Int32 instead of string in case of only one item attached to MNTP

    @foreach (var bannerID in CurrentPage.banner.Split(',')) {
              dynamic banner = Umbraco.Content(bannerID);
    }
    

    any suggestion or i must be use .ToString() to force the cast from Int32 to String in case of only one item?

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 02, 2013 @ 15:30
    Jeavon Leopold
    0

    Hi Alessandro,

    Yes, I think that is a bug and I'l report it as such unless you have already?

    This would be my suggested snippet for MNTP in v7 using Dynamics:

    @{
        var bannerList = CurrentPage.banner.ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
        var bannerListCollection = Umbraco.Content(bannerList);
        foreach (var item in bannerListCollection)
        {
            <p>here: @item.Name</p>
        }
    }
    

    Jeavon

  • Alessandro 21 posts 51 karma points
    Dec 02, 2013 @ 15:58
    Alessandro
    0

    Thanks Jeavon i don't report it already. Meantime, thanks for the suggested snippet

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 02, 2013 @ 16:15
    Jeavon Leopold
    0

    No worries, issue created here

Please Sign in or register to post replies

Write your reply to:

Draft