Copied to clipboard

Flag this post as spam?

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


  • Silvija 58 posts 171 karma points
    Apr 08, 2019 @ 12:33
    Silvija
    0

    Cant get members MNTP values

    I am realy stuck with this for days... I am trying to get a list of members with their Multinode tree picker values. This is my code:

       var member = Services.MemberService.GetAllMembers();
    
    @foreach (var item in member)
    {
            var typedMultiNodeTreePicker = Model.Value<IEnumerable<IPublishedContent>>("categoryPicker");
            foreach (var category in typedMultiNodeTreePicker)
            {
                <p>@category.Name</p>
            }
    
        <p>@item.Email</p>
    
    }
    

    But i am getting this error: enter image description here

  • Johannes Lantz 123 posts 610 karma points c-trib
    Apr 08, 2019 @ 17:31
    Johannes Lantz
    0

    Hi Silvija!

    Is it the member that has the Multinode treepicker? in that case

    Try changing :

    var typedMultiNodeTreePicker = Model.Value<IEnumerable<IPublishedContent>>("categoryPicker");
    

    To:

    var typedMultiNodeTreePicker = item.Value<IEnumerable<IPublishedContent>>("categoryPicker");
    

    Let me know if it works!

    //Johannes

  • Silvija 58 posts 171 karma points
    Apr 08, 2019 @ 20:21
    Silvija
    0

    Hi Johannes,

    Yes, its MNTP member custom property. When I try your suggestion i am getting this compilation error: enter image description here

  • Johannes Lantz 123 posts 610 karma points c-trib
    Apr 09, 2019 @ 06:22
    Johannes Lantz
    0

    I belive it should be

    var typedMultiNodeTreePicker = item.GetProperty<IEnumerable<IPublishedContent>>("categoryPicker");
    

    Since we want to the members property we have to use "item". Since Model is "Currentpage" and the "Currentpage" dosen't have the property value "categoryPicker"

    //Johannes

  • Silvija 58 posts 171 karma points
    Apr 09, 2019 @ 09:38
    Silvija
    0

    I tried that too but i am getting this message:

    enter image description here

    Probably i am missing namespace , but i dont know which one. This is what i have now:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    

    @using ContentModels = Umbraco.Web.PublishedModels;

  • Johannes Lantz 123 posts 610 karma points c-trib
    Apr 09, 2019 @ 09:51
    Johannes Lantz
    0

    Not to sure on Umbraco 8, but 7 is

    @using Umbraco.Web
    

    //Johannes

  • Silvija 58 posts 171 karma points
    Apr 09, 2019 @ 10:09
    Silvija
    0

    Unfortunately its still the same :/

  • Johannes Lantz 123 posts 610 karma points c-trib
    Apr 09, 2019 @ 16:56
    Johannes Lantz
    0

    I have done some testing of this myself, I the closest that I have gotten it this.

    var typedMultiNodeTreePicker = member.GetValue<IEnumerable<IPublishedContent>>("categoryPicker");
    

    But this returns null, but maybe it will work for you?

    Otherwise I am unfortunately out of idéa :(

    //Johannes

  • Silvija 58 posts 171 karma points
    Apr 09, 2019 @ 17:47
    Silvija
    0

    When I try it that way i am getting this: enter image description here

    It says:

    Severity Code Description Project File Line Suppression State Error CS1929 'IEnumerable

    I alredy tried this before but with no luck.

    Still thank you Johannes for the effort.

    Silvija

  • Silvija 58 posts 171 karma points
    Apr 11, 2019 @ 19:02
    Silvija
    0

    I'm still struggling with this. This is the closest I came to:

    @{
        var member = Services.MemberService.GetAllMembers();
    }
    
    @foreach (var item in member)
    {
    
        var typedMultiNodeTreePicker = item.GetValue<IEnumerable<IPublishedContent>>("categoryPicker");
        if (typedMultiNodeTreePicker != null)
        {
            foreach (var category in typedMultiNodeTreePicker)
            {
                <p>@category.Name</p>
    
            }
        }
        @item.Name
        @item.GetValue("phoneNumber")
    }
    

    Anybody else have any idea? I really got stuck. Thanks

  • Nik 1512 posts 6679 karma points MVP 5x c-trib
    Apr 11, 2019 @ 20:18
    Nik
    2

    Okay, so it looks like PropertyValueConverters don't kick in on Members.

    The MultiNodeTreePicker is storing the selection as a string of UDI's separated by a comma.

    So you'll have to split the string on the comma and then loop around each entry and then retrieve the IPublishedContent for the categories you are trying to retrieve.

    I think "something" like this but there will be errors in my code

    var categoriesString = item.GetValue<string>("categoryPicker");
    foreach(var categoryString in categoriesString.Split(','))
    {
        var category = Umbraco.Content(categoryString);
    }
    

    Additional Info - Untested

    I think part of the issue is how you are getting the Members, if you were getting individual Members using the MembershipHelper they come back as IPublishedContent entries, in which case I suspect the PropertyValueConverters would kick in and what you were trying would work.

  • Silvija 58 posts 171 karma points
    Apr 12, 2019 @ 09:27
    Silvija
    0

    Hi Nik,

    Thank you so much for this input. I made some progress, but forgive me if I did not correctly implement your solution.

    This is my code right now:

    @foreach (var item in member)
    {
        var typedMultiNodeTreePicker = item.GetValue<string>("categoryPicker");
        if (typedMultiNodeTreePicker != null)
        {
            foreach (var category in typedMultiNodeTreePicker.Split(','))
            {
                <p>@category</p>
            }
        }
    

    This is the result of it:

    umb://document/7bf41d847bbe45188dc9b61b406e3445
    
    umb://document/0a19cdbaa84b442c9fb7db33b6f5ccc5
    
    umb://document/7656d5ad68cb4720b221854e1ddf6164
    

    I have guids here after document/ , now i need to cut this guid and convert it , or something like that.

  • Silvija 58 posts 171 karma points
    Apr 12, 2019 @ 11:38
    Silvija
    1

    After hours of torture, finaly i found the solution.

        @foreach (var item in member)
    {  
        var typedMultiNodeTreePicker = item.GetValue<string>("categoryPicker");
        if (typedMultiNodeTreePicker != null)
        {
            foreach (var udi in typedMultiNodeTreePicker.Split(','))
            {
                var categories = Umbraco.Content(Udi.Parse(udi)).DescendantsOrSelf()
                                                 .Where(x => x.IsVisible()).ToArray(); ;
    
                foreach (var category in categories)
                {
                        <a  href="@category.Url">@category.Name</a><br />
                 }
            }    
        }
        @item.Name <br />
        @item.GetValue("phoneNumber") <br />
        @item.Email
    }
    

    I'm sure this is not the best solution so if someone has some suggestion for improvement please suggest it here :)

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft