Copied to clipboard

Flag this post as spam?

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


  • Mads Sørensen 188 posts 433 karma points
    Jul 05, 2016 @ 10:14
    Mads Sørensen
    0

    MNTP - Split id's

    Hi I would like to split the Id's from selected nodes in the MNTP like so:

    <div class="item" data-ids="1001 1002 1003"><a href="#"></a></div>
    

    Right now my code looks like this

    @foreach(var item in CurrentPage.Children().Where("Visible")){
    
        var optionList = item.kompetencer.ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
        var optionCollection = Umbraco.Content(optionList);
    
        var list = new List<string>();
    
        foreach (var node in optionCollection){
          list.Add(node.Id.ToString());
        }
    
        <div class="item" data-ids="@list"><a href="#">@item.Name</a></div>
    
      }
    

    And it gives me the following output

    <div class="item" data-ids="System.Collections.Generic.List`1[System.String]"><a href="#">Test Reference</a></div>
    

    Hope some one can give me some directions :)

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jul 05, 2016 @ 11:04
    Lee Kelleher
    100

    Hi Mads,

    The @list will need to be joined together using a space, like so...

    <div class="item" data-ids="@(string.Join(" ", list))"><a href="#">@item.Name</a></div>
    

    I hope this helps?

    Cheers,
    - Lee

  • Mads Sørensen 188 posts 433 karma points
    Jul 05, 2016 @ 11:08
    Mads Sørensen
    0

    Hi Lee Thanks that made my day :)

    Is there a reference how to handle json data :D

    Cheers ,-

    Mads

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jul 05, 2016 @ 11:10
    Lee Kelleher
    0

    JSON data, how do you mean? As in JSON coming from an Umbraco node property? or that you want to construct a JSON object in your Razor view?

  • Mads Sørensen 188 posts 433 karma points
    Jul 05, 2016 @ 11:14
    Mads Sørensen
    0

    I was quite sure that the MNTP output was JSON data :) But maybe i was wrong :)

Please Sign in or register to post replies

Write your reply to:

Draft