Copied to clipboard

Flag this post as spam?

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


  • Splinx 50 posts 186 karma points
    Mar 02, 2018 @ 11:48
    Splinx
    0

    Querying multinodetreepicker2 from startuphandler

    Hi Guys,

    I have found myself in the unenviable position of upgrading an Umbraco site produced by another set of developers.

    Umbraco 7 seems absolutely fantastic so far but I have just a few areas that I'm really struggling with...

    The previous developers created a json file on startup that lists a large number of regions and countries etc.. that is then used for Google maps.

    The challenge is that the countries are linked to regions with the "multinodetreepicker" and the Umbraco 6 site currently works with this code:

    countries = @item.HasValue("countries") ? Umbraco.TypedContent(@item.GetPropertyValue("countries").ToString().Split(',')).Where("Visible").OrderBy("Name").Select(c => new
     {
            id = c.Id,
            name = c.GetPropertyValue(Localise.Localise.GetPropAlias(c, "countryName", Culture)),
            isocode = c.GetPropertyValue("isoCode"),
    

    My Challenge is that this worked on Umbraco 6 with the multinodetreepicker (not version 2) but the MultinodeTreepicker2 doesn't seem to return any countries even though they are in the CMS.enter image description here

    Is there a better way that I should be querying this data and perhaps not using "Umbraco.TypedContentAtXPath" at all?

    I've been trying to use the examples and excellent support items already in the forum but I cannot seem to find anything that helps me with this specific challenge; especially since this code doesn't seem to be able to use content.Model ???


    I'm sorry if I'm not asking the question correctly or misunderstanding Umbraco.

    Thanks in advance,

    Splinx

  • Splinx 50 posts 186 karma points
    Mar 04, 2018 @ 16:01
    Splinx
    101

    Hi Guys,

    Fixed this myself by simply taking some time to understand Umbraco (and .net in general) a little more.

    posting the fix just in case it helps anyone else.

    Cheers, Splinx

      countries = item.GetPropertyValue<IEnumerable<IPublishedContent>>("countries").Any() ?
    item.GetPropertyValue<IEnumerable<IPublishedContent>>("countries").Select(c => new
          {
        id = c.Id,
        name = c.GetPropertyValue(Localise.Localise.GetPropAlias(c, "countryName", Culture)),
        isocode = c.GetPropertyValue("countryIsoCode")
    
Please Sign in or register to post replies

Write your reply to:

Draft