Copied to clipboard

Flag this post as spam?

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


  • Scott Hugh Alexandar Petersen 87 posts 235 karma points
    Oct 26, 2018 @ 12:40
    Scott Hugh Alexandar Petersen
    0

    Multi Node Tree Picker 2

    Hi everybody,

    Umbraco 7.12.3

    I'm having trouble with mntp2 and I wondered if you guys could give me a hand.

    I have this code which works fine when enablepropertyvalueconverters is disabled but not enabled. I am working on a partial view which is used in templates.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using Umbraco.Core.Dynamics;
    @using ClientDependency.Core.Mvc;
    
    // string vbField = "columnRightBoxes"
    // bool vbRecursive = true
    string mntp = Umbraco.Field(vbField, recursive: vbRecursive).ToString();
    // mntp returns: System.Collections.Generic.List`1[Umbraco.Core.Models.IPublishedContent]
    
    List<string> mntpList = new List<string>();
    foreach (dynamic id in mntp.Split(','))                
    {
        mntpList.Add(id); 
    }
    
    IEnumerable<IPublishedContent> typedMNTPCollection = Umbraco.TypedContent(mntpList).Where(x => x != null);
    foreach (IPublishedContent item in typedMNTPCollection)
    {
    }
    

    So how do I loop through mntp2

    I tried with Model.Content.ColumnRightBoxes but got an null exception.

    I can easily get it to work with content picker but not multi node content picker.

    Thanks

  • Garðar Þorsteinsson 98 posts 473 karma points
    Oct 26, 2018 @ 13:00
    Garðar Þorsteinsson
    0

    Hi Scott,

    Try this

    var multiNodeItem = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("propertyAlias");
    
    foreach (var item in multiNodeItem)
    {
        <p>@item.Name</p>
    }
    
  • Scott Hugh Alexandar Petersen 87 posts 235 karma points
    Oct 26, 2018 @ 13:04
    Scott Hugh Alexandar Petersen
    0

    Hi Garðar

    I did look to the documentation but it does not work.

    Basically I have created a document type with a mntp2 in it.

    Then I have created a partial view which is called from a template.

    Then I have created a page where I have selected in this case just one other page using the mntp2 but no luck.

  • Garðar Þorsteinsson 98 posts 473 karma points
    Oct 26, 2018 @ 13:08
    Garðar Þorsteinsson
    0

    Maybe you could try to publish the node again or restart the application. I have had it happened that I need to restart the application for the values to be returned correctly.

    Do you get an error or is there just nothing in the list ?

  • Scott Hugh Alexandar Petersen 87 posts 235 karma points
    Oct 26, 2018 @ 13:09
    Scott Hugh Alexandar Petersen
    0

    Did that as well.

    It works when pasted into the template file

  • Scott Hugh Alexandar Petersen 87 posts 235 karma points
    Oct 26, 2018 @ 13:12
    Scott Hugh Alexandar Petersen
    0

    Clarification:

    What is in the documentation works when executed from the template but not from the partial view

  • Scott Hugh Alexandar Petersen 87 posts 235 karma points
    Oct 26, 2018 @ 13:14
    Scott Hugh Alexandar Petersen
    0

    I get this error:

    Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    Line 12: *@ Line 13: Line 14: @{ var selection = Model.Content.GetPropertyValue<>

    And that is using the stock examples from Umbraco

  • Garðar Þorsteinsson 98 posts 473 karma points
    Oct 26, 2018 @ 13:16
    Garðar Þorsteinsson
    0

    Hmmm thats odd.

    How are you calling the partial from the template ?

    If you write out @Model.Content.GetPropertyValue("propertyField") does it say System.Collections.Generic.List`1[Umbraco.Core.Models.IPublishedContent] ?

    Can you check if the Model.Content is null or actually the list ?

  • Scott Hugh Alexandar Petersen 87 posts 235 karma points
    Oct 26, 2018 @ 13:18
    Scott Hugh Alexandar Petersen
    0

    I actually just tried to call it differently

    // this does not work due to passing variables and no content model @Html.Partial("Boxes", new ViewDataDictionary { { "field", "columnRightBoxes" }, { "recursive", true } })

    // this works due to NOT passing variables thus the content model is not overwritten @Html.Partial("Boxes")

    Can I pass the content model on and the variables as well?

  • Scott Hugh Alexandar Petersen 87 posts 235 karma points
    Oct 26, 2018 @ 13:20
    Scott Hugh Alexandar Petersen
    100

    I changed it to:

    @Html.Partial("Boxes", Model.Content, new ViewDataDictionary { { "field", "columnRightBoxes" }, { "recursive", true } })

    Now I'll change the script

  • Scott Hugh Alexandar Petersen 87 posts 235 karma points
    Oct 26, 2018 @ 20:48
    Scott Hugh Alexandar Petersen
    0

    By the way Garðar, thanks for pitching in!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies