Copied to clipboard

Flag this post as spam?

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


  • Tara Pattenden 44 posts 205 karma points
    Oct 09, 2020 @ 03:10
    Tara Pattenden
    0

    Accessing properties of a multinodetree picker

    Hi

    I have a content node with a multinodetree picker With the following code I can access the name (and also url etc) of the content node. How do i access the other properties? This code works to show the name - NowShowing is the alias for the multinodetree picker

    <section>
        @{
            var nowShow = Model.NowShowing;
            var artists = "artistsInvolved";
    
        }
    
        <h3>
            @nowShow.Name
    
        </h3>
    </section>
    

    The alias of the property I wish to access is "artistsInvolved" I have tried the following code

    <section>
        @{
            var nowShow = Model.NowShowing;
            var artists = "artistsInvolved";
    
        }
    
        <h3>
            @nowShow.GetPropertyValue("artistsInvolved")
    
        </h3>
    </section>
    

    which returns the following text on the front end>>> System.Collections.Generic.List`1[Umbraco.Core.Models.IPublishedContent]

    I have also tried the following but it returns an error

    <section>
        @{
            var nowShow = Model.NowShowing;
            var artists = "artistsInvolved";
    
        }
    
        <h3>
            @nowShow.GetPropertyValue<string>("artistsInvolved")
    
        </h3>
    </section>
    

    I have also tried this but I get an error with the use of Content.

      @{var typedMultiNodeTreePicker = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("artistsInvolved");
        }
    

    This is the error message 'PublishedContentWrapped.Content' is inaccessible due to its protection level

    Thanks for any help

  • Tara Pattenden 44 posts 205 karma points
    Oct 09, 2020 @ 04:02
    Tara Pattenden
    0

    I'll leave this here for reference but I was trying to access a property of the content node that didn't exist - artistsInvolved

    so my original code seems to have been correct...

  • Tara Pattenden 44 posts 205 karma points
    Oct 09, 2020 @ 04:20
    Tara Pattenden
    0

    Actually now i have tried to do the same thing on a sibling content node that also uses the same multinode tree picker.

    However for some reason it says that I can't use GetPropertyValue with this one.

    I get the following error when i try Error CS1929 'IEnumerable

    I think there is an underlying concept that I don't understand because I am baffled as to why it works on one content node but not another. If anyone can help me understand that would be amazing

  • Tara Pattenden 44 posts 205 karma points
    Oct 09, 2020 @ 04:30
    Tara Pattenden
    0

    When i look at the generated models for the two content nodes. they seem to access the content differently - I really don't know why I'm reusing the same picker

    here is the one that is working

    [ImplementPropertyType("nowShowing")]
            public IPublishedContent NowShowing
            {
                get { return this.GetPropertyValue<IPublishedContent>("nowShowing"); }
            }
    

    Here is the section from the model that is not working

    [ImplementPropertyType("streamProgram")]
            public IEnumerable<IPublishedContent> StreamProgram
            {
                get { return this.GetPropertyValue<IEnumerable<IPublishedContent>>("streamProgram"); }
            }
    

    just gonna check i'm not trying to access content that doesn't exist but any pointers would be great

  • Tara Pattenden 44 posts 205 karma points
    Oct 09, 2020 @ 04:34
    Tara Pattenden
    0

    Ok So I have solved it and I'm putting what I did wrong here for others. I think this may be specific to v7.

    The first one i was using was a content picker not a multinode picker

    the second one which wasn't working was a multinode picker

    so for now I'll stick with content picker

    phewwww. hope that helps some other noob. stay tuned for more please help posts :P

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Oct 09, 2020 @ 05:12
    Nik
    1

    Hi Tara,

    I thought I'd jump in and try and explain the differences to you :-)

    The Content Picker is returning only a singular content node, so it's return type is an IPublishedContent singular. That is why when you do

    var value = myNodes.MyContentPicker;
    

    you are able to successfully do

    var valueName = value.Name
    

    afterwards.

    However, MultiNodeTreePickers (or MNTP for short), returns a collection of IPuublishedContents.

    This means you need to treat the result like a list and do something like this:

    @foreach(var node in myModel.MyMultiNodeTreePickerProperty)
    {
            <div>@node.Name</div>
            <div>@node.GetPropertyValue("aDifferentPropertyOnTheNode)</div>
    }
    

    Does that help with you understanding?

    Cheers,

    Nik

  • Tara Pattenden 44 posts 205 karma points
    Oct 09, 2020 @ 05:32
    Tara Pattenden
    0

    This is what i am first trying

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<StreamingEvent>
    
    @{
        Layout = "Master.cshtml";
        var thisStream = Model.StreamProgram;
        var streamArtists = thisStream.GetPropertyValue("artistsInvolved");
    
    }
    
    <h1 class="text-center">Live-on-the-Line: @thisStream.GetPropertyValue("smallTitle")</h1>
    <iframe src="https://player.vimeo.com/video/@Model.EmbedCode" width="640" height="360" frameborder="0" allow="autoplay; fullscreen" allowfullscreen></iframe>
    
    
    <section>
    
    
        <h4 class="heading"> About @thisStream.GetPropertyValue("smallTitle")</h4>
    
        <p>@thisStream.GetPropertyValue("mainProgramDescription")</p>
        <h4 class="heading mb0">Artists</h4>
    
    
        @foreach (var item in streamArtists)
        {
            <p>@item.Name</p>}
    
    
    </section>
    

    but i am getting an error on streamArtists and a following error that the name property doesn't exist.

    CS1579 foreach statement cannot operate on variables of type 'object' because 'object' does not contain a public instance definition for 'GetEnumerator'

  • Tara Pattenden 44 posts 205 karma points
    Oct 09, 2020 @ 05:34
    Tara Pattenden
    0

    On the program page which is a pre-existing page that renders the artists. the artists are rendered like this. which I am guessing involves some custom stuff and that's why Artist is written before item. Do you have any insight?

      <h4 class="heading mb0">Artists</h4>
    
                    @foreach (Artist item in Model.ArtistsInvolved)
                    {
                        <a href="@item.Url" class="text-light">@item.getName()</a> <br />}
    
                    <hr class="border-dark" />
    
  • Tara Pattenden 44 posts 205 karma points
    Oct 09, 2020 @ 05:36
    Tara Pattenden
    0

    Hi

    Yes that helps thanks. I'm going to have a look over this. I have another related question though

    my content from the content picker contains a MNTP and I am trying to access that content now and struggling.

  • Tara Pattenden 44 posts 205 karma points
    Oct 09, 2020 @ 05:48
    Tara Pattenden
    0

    oh and here is where it is referenced in the model that's generated

    ///<summary>
            /// Artists Involved: The artists responsible for this program
            ///</summary>
            [ImplementPropertyType("artistsInvolved")]
            public IEnumerable<IPublishedContent> ArtistsInvolved
            {
                get { return this.GetPropertyValue<IEnumerable<IPublishedContent>>("artistsInvolved"); }
            }
    
  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Oct 09, 2020 @ 05:50
    Nik
    100

    Hi Tara,

    You could try the following:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<StreamingEvent>
    
    @{
        Layout = "Master.cshtml";
        var thisStream = Model.StreamProgram;
        var streamArtists = thisStream.GetPropertyValue<IEnumerable<IPublishedContent>>("artistsInvolved"); //First change here
    
    }
    
    <h1 class="text-center">Live-on-the-Line: 
    @thisStream.GetPropertyValue("smallTitle")</h1>
    <iframe src="https://player.vimeo.com/video/@Model.EmbedCode" width="640" height="360" frameborder="0" allow="autoplay; fullscreen" allowfullscreen></iframe>
    
    <section>
        <h4 class="heading"> About @thisStream.GetPropertyValue("smallTitle")</h4>
    
        <p>@thisStream.GetPropertyValue("mainProgramDescription")</p>
        <h4 class="heading mb0">Artists</h4>
    
    
        //This should now work
        @foreach (var item in streamArtists)
        {
            <p>@item.Name</p>}
    
    
    </section>
    

    Now, at the minute things are a little harder than maybe they need to be. So, what you could do is take advantage of something call Models Builder and strongly typed models and do this:

    Instead of

     var streamArtists = thisStream.GetPropertyValue<IEnumerable<IPublishedContent>>("artistsInvolved");
    

    you could do

    var streamArtists = thisStream.GetPropertyValue<IEnumerable<Artist>>("artistsInvolved");
    

    This will strongly type the items in streamArtist to be of type Artist, so when you access them you shouldn't need to use .GetPropertyValue to access the custom properties, but you could do something like artist.MyProperty (assuming MyProperty exists on it).

    Does that help?

  • Tara Pattenden 44 posts 205 karma points
    Oct 09, 2020 @ 05:52
    Tara Pattenden
    0

    That is all starting to make sense. Thanks so much - I'm going to try it now The rest of the site is strongly typed and I like the shortness of it so that looks like the way forward. I'll be reporting back soon

  • Tara Pattenden 44 posts 205 karma points
    Oct 09, 2020 @ 06:05
    Tara Pattenden
    0

    Hi again Nik i'll repost what i posted in reply to your second comment

    Thanks

    First a question, how are "types" set - is artist a type because it's a doc-type?

    I've tried updating the code and with the first (not strongly typed method) I am getting no errors but no content shows, I've double checked and there is content that should show

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<StreamingEvent>
    
    @{
        Layout = "Master.cshtml";
        var thisStream = Model.StreamProgram;
        var streamArtists = thisStream.GetPropertyValue<IEnumerable<IPublishedContent>>("artistsInvolved");
    
    
    }
    
    <h1 class="text-center">Live-on-the-Line: @thisStream.GetPropertyValue("smallTitle")</h1>
    <iframe src="https://player.vimeo.com/video/@Model.EmbedCode" width="640" height="360" frameborder="0" allow="autoplay; fullscreen" allowfullscreen></iframe>
    
    
    <section>
    
    
        <h4 class="heading"> About @thisStream.GetPropertyValue("smallTitle")</h4>
    
        <p>@thisStream.GetPropertyValue("mainProgramDescription")</p>
        <h4 class="heading mb0">Artists</h4>
    
    
        @foreach (var item in streamArtists)
        {
            <p>@item.Name</p>}
    
    
    </section>
    

    I've also tried to change the variable so it will worked with strongly typed but I don't know how to call the artists then. there is a property called first name but I am not getting any suggestions from intellisense for .Name or .firstName

    like so

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<StreamingEvent>
    
    @{
        Layout = "Master.cshtml";
        var thisStream = Model.StreamProgram;
        var streamArtists = thisStream.GetPropertyValue<IEnumerable<Artist>>("artistsInvolved");
    
    
    }
    
    <h1 class="text-center">Live-on-the-Line: @thisStream.GetPropertyValue("smallTitle")</h1>
    <iframe src="https://player.vimeo.com/video/@Model.EmbedCode" width="640" height="360" frameborder="0" allow="autoplay; fullscreen" allowfullscreen></iframe>
    
    
    <section>
    
    
        <h4 class="heading"> About @thisStream.GetPropertyValue("smallTitle")</h4>
    
        <p>@thisStream.GetPropertyValue("mainProgramDescription")</p>
        <h4 class="heading mb0">Artists</h4>
    
    
        @foreach (var item in streamArtists)
        {
            <p>@Artist.firstName</p>}
    
    
    </section>
    
  • Tara Pattenden 44 posts 205 karma points
    Oct 09, 2020 @ 06:16
    Tara Pattenden
    0

    Also I'm not sure if this is my issue but "artistsInvolved" is the alias for the MNTP

    I am now able to have the strongly typed code with no errors and i can see firstName suggested! but I am getting an error on the front end

    my code

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<StreamingEvent>
    
    @{
        Layout = "Master.cshtml";
        var thisStream = Model.StreamProgram;
        var streamArtists = thisStream.GetPropertyValue<IEnumerable<Artist>>("artistsInvolved");
    
    
    }
    
    <h1 class="text-center">Live-on-the-Line: @thisStream.GetPropertyValue("smallTitle")</h1>
    <iframe src="https://player.vimeo.com/video/@Model.EmbedCode" width="640" height="360" frameborder="0" allow="autoplay; fullscreen" allowfullscreen></iframe>
    
    
    <section>
    
    
        <h4 class="heading"> About @thisStream.GetPropertyValue("smallTitle")</h4>
    
        <p>@thisStream.GetPropertyValue("mainProgramDescription")</p>
        <h4 class="heading mb0">Artists</h4>
    
    
        @foreach (var item in streamArtists)
        {
            <p>@item.FirstName</p>
            }
    
    
    </section>
    

    the browser error - although it doesn't really help

    Server Error in '/' Application.
    Configuration Error
    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
    
    Parser Error Message: The value of the property 'mode' cannot be parsed. The error is: The enumeration value must be one of the following: RemoteOnly, On, Off.
    
    Source Error:
    
    
    Line 92:   <system.web>
    Line 93:     <!-- <customErrors mode="Off" /> -->
    Line 94:     <customErrors mode="off" defaultRedirect="~/error.aspx">
    Line 95:       <error statusCode="404" redirect="~/error.aspx" />
    Line 96:     </customErrors>
    
    
    Source File: C:\Users\Tara\Documents\lw2\pspace-2020\PerformanceSpace\web.config    Line: 94
    
  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Oct 09, 2020 @ 05:52
    Nik
    1

    As for some explanation,

    If you make a call to GetPropertyValue and you don't specify a type, the returned type is "object", however, if you want to specific things with the item(s), you really need to be returning a known type, in this case we know that MNTP's store their results as IEnumerable<IPublishedContent> so we can tell GetPropertyValue this by calling it like this: GetPropertyValue<IEnumerable<IPublishedContent>>.

    If we wanted to get an integer out of the property because we knew that was what was being store then we could do GetPropertyValue<int> for example.

  • Tara Pattenden 44 posts 205 karma points
    Oct 09, 2020 @ 05:59
    Tara Pattenden
    0

    Thanks

    First a question, how are "types" set - is artist a type because it's a doc-type?

    I've tried updating the code and with the first (not strongly typed method) I am getting no errors but no content shows, I've double checked and there is content that should show

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<StreamingEvent>
    
    @{
        Layout = "Master.cshtml";
        var thisStream = Model.StreamProgram;
        var streamArtists = thisStream.GetPropertyValue<IEnumerable<IPublishedContent>>("artistsInvolved");
    
    
    }
    
    <h1 class="text-center">Live-on-the-Line: @thisStream.GetPropertyValue("smallTitle")</h1>
    <iframe src="https://player.vimeo.com/video/@Model.EmbedCode" width="640" height="360" frameborder="0" allow="autoplay; fullscreen" allowfullscreen></iframe>
    
    
    <section>
    
    
        <h4 class="heading"> About @thisStream.GetPropertyValue("smallTitle")</h4>
    
        <p>@thisStream.GetPropertyValue("mainProgramDescription")</p>
        <h4 class="heading mb0">Artists</h4>
    
    
        @foreach (var item in streamArtists)
        {
            <p>@item.Name</p>}
    
    
    </section>
    
  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Oct 09, 2020 @ 06:47
    Nik
    1

    Hi Tara,

    Can you confirm that the ArtistsInvolved property on your Stream Program is in fact a MultiNodeTreePicker property, I ask because that code should work. Can you also check that the stream program you are looking at has artists picked in the Artists Involved property.

    Sometimes these things can be harder to diagnose without seeing the entire code base/backoffice set up to understand exactly what is going on.

    With regards to your first question how are "types" set - is artist a type because it's a doc-type?, it's not the easiest thing to explain.

    If you site has Models Builder enabled, then all doc types are converted to models, in addition, if something called PropertyValueConverter's (PVC) are enabled, then other things are converted to models/collections and similar as well.

    For example, a MNTP stores the picked data in the database as an array of UDI's I believe. With Models Builder and PropertyValueConverters enabled, the generated representation of a MNTP Property on a doc type is IEnumerable<IPublishedContent>>. If PropertyValueConverter's weren't enabled, I believe it would just be a string. These day's however it's unusual to find sites without Models Builder and without PropertyValueConverters being enabled.

    The PVC's are the functionality that converts the stored data for a property into a model of some description.

    Does that help?

  • Tara Pattenden 44 posts 205 karma points
    Oct 09, 2020 @ 07:05
    Tara Pattenden
    0

    ok so I am just checking this now I am using models builder in case that is useful (liveapp version)

    Streaming event is a doc_type I created. streamProgram is a content picker that picks from doctypes program

    artistsInvolved is on the program doctype and is a multinode tree picker that allows items of type artist. - Umbraco.MultiNodeTreePicker2

    There are 3 artists selected in the content node that I selected in StreamProgram

    I'm still getting the brower error (but none in visual studio) when i use the following code

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<StreamingEvent>
    
    @{
        Layout = "Master.cshtml";
        var thisStream = Model.StreamProgram;
        var streamArtists = thisStream.GetPropertyValue<IEnumerable<Artist>>("artistsInvolved");
    
    
    }
    
    
                <h4 class="heading mb0">Artists</h4>
    
                @foreach (var item in streamArtists)
                {
                    <p>@item.FirstName</p>
                }
    

    I'll just test the other method again. The site I am working on seems to have custom models built as well, although the artist one is a generated one. not sure if that is useful info.

  • Tara Pattenden 44 posts 205 karma points
    Oct 09, 2020 @ 07:10
    Tara Pattenden
    0

    And using the long typed method I don't get any thing on the front end showing up.

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<StreamingEvent>
    
    @{
        Layout = "Master.cshtml";
        var thisStream = Model.StreamProgram;
        var streamArtists = thisStream.GetPropertyValue<IEnumerable<IPublishedContent>>("artistsInvolved");
    
    
    }
    
                <h4 class="heading mb0">Artists</h4>
    
                @foreach (var item in streamArtists)
                {
                    <p>@item.GetPropertyValue("firstName")</p>
                }
    

    I've also tried it with only

    @item.Name
    

    and nothing shows up which is perhaps telling that I'm not accessing the data?

    really appreciating your help on this, thanks

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Oct 09, 2020 @ 07:18
    Nik
    1

    Hi Tara,

    Okay, let's try something here based on the information you've provided:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<StreamingEvent>
    
    @{
           Layout = "Master.cshtml";
           var streamProgramme = Model.StreamProgam as Program;
           var artistsInvolved = streamProgramme?.ArtistsInvolved;
    
    }
    
    @if(artistsInvolved != null && artistsInvolved.Any(a => a != null && a is Artist))
    {
        <h4 class="heading mb0">Artists</h4>
        @foreach(Artist artist in artistsInvolved)
        {
              <p> @artist.Name -  @artist.FirstName</p>
        }
    }
    else
    {
         <div>No Artists found</div>
    }
    

    Let's see if that renders anything out. It looks a bit more complicated, maybe, but I've added in some null checks and things as well as tried to keep things strongly typed based on the information you've provided.

    See if that works, or if you get the No Artists Found message.

  • Tara Pattenden 44 posts 205 karma points
    Oct 09, 2020 @ 07:32
    Tara Pattenden
    1

    Ok well that helps because I am getting no artist found. I double checked the program and it did have artists

    Then I just changed the program to a different one that also has artists listed and it worked for that one.

    Maybe there were two programs with the same name and different content or I'm not sure but It is there and working now.

    Thanks so much for your patience and help with this. I've learned loads and not torn my hair out too much :)

    I am working on an local version but the data is from last year and there are a few tricky things set up by the original developer so maybe a date was wrong and invalidated the program i originally chose...

    anyway - it's sorted !!! yay

    again thanks a billion, you're a lifesaver.

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Oct 09, 2020 @ 07:33
    Nik
    0

    No problem at all, pleased it's working for you :-)

  • Tara Pattenden 44 posts 205 karma points
    Oct 09, 2020 @ 07:32
    Tara Pattenden
    0

    I will mark your earlier comment as the solution

Please Sign in or register to post replies

Write your reply to:

Draft