Copied to clipboard

Flag this post as spam?

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


  • James Inger 11 posts 102 karma points
    Nov 04, 2018 @ 21:57
    James Inger
    0

    Get Multiple Images from Media Picker from another Model

    I have a Master template which has the header and footer for each page.

    Each page thereafter is rendered inside that Master template using @RenderBody().

    In the Hompage Model I have a media picker using multiple images.

    I can call the media picker on the homepage but not on any other page

    Works on hompega eusing the following

     @{   var typedMultiMediaPicker = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("asscoiates_logos_slider");
    
      foreach (var item in typedMultiMediaPicker)
       {
        var URL = item.GetPropertyValue<string>("imageURL");
        <div>
        <a href="@URL" target="_blank"><img src="@item.Url" alt="" /></a>
       </div>
         }
         }
    

    When displaying from a page that is not the homepage i get error

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

    Im thinking its because the properties are set on the homepage therefore works on home page.

    Otherwise : How do I do recursive with multiple images with media picker.

  • Alex Skrypnyk 5908 posts 22603 karma points MVP 4x admin c-trib
    Nov 05, 2018 @ 08:40
    Alex Skrypnyk
    100

    Hi James

    Where media picker placed? Is it on the home page node?

    I think you have to call media picker in the home page like that:

    var homePage = Umbraco.AssignedContentItem.AncestorOrSelf(1);
    
    var typedMultiMediaPicker = homePage.GetPropertyValue<IEnumerable<IPublishedContent>>("asscoiates_logos_slider");
    

    Alex

  • James Inger 11 posts 102 karma points
    Nov 05, 2018 @ 19:38
    James Inger
    1

    Awesome Alex, that's the ticket.

    I had that same idea as well but using different code which was wrong, perfect - Thanks a lot :)

  • 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