Copied to clipboard

Flag this post as spam?

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


  • Brian 30 posts 171 karma points
    Aug 10, 2020 @ 16:05
    Brian
    0

    Use Media Picker for PostImage Field

    Hello Support,

    I know this question has been asked before but the only solutions I could find were for old version of Umbraco from several years back and an open GitHub issue (https://github.com/Shazwazza/Articulate/issues/339) that only partially answers this question.

    I changed the Articulate data type for postImage from an Image Upload to a Media Picker and renamed it from postImage to postImageTest then imported about 100 posts from another platform and assigned the Post Image to each posts' respective image.

    My issue is how to work with this field in the List.cshtml file. I created a custom theme from a copy of one of the provided themes and have tried everything I could think of to get this field to pull in to my Razor code.

    foreach (var post in Model.Posts)
    

    When trying to follow the Umbraco docs for the Media Picker and various suggestions (post.Value("postImageTest"), post.GetPropertyValue("postImageTest"), var thumbnail = post.Value<IPublishedContent>("postImageTest");) I couldn't get anything to work correctly and all produced a Compilation Error screen.

    The error I receive when using post.Value<IPublishedContent>("postImageTest"); is as follows:

    Compiler Error Message: CS0246: The type or namespace name 'IPublishedContent' could not be found (are you missing a using directive or an assembly reference?)
    

    The closest I've come to success is the following:

    var thumbnail = post.Value("postImageTest");
    <p>image: @thumbnail</p>
    

    Which outputs image: Umbraco.Web.PublishedModels.Image on my page but I can't access any properties like thumbnail.Url or thumbnail.GetPropertyValue("Url") or thumbnail.Value("Url") without getting an error that none of those definitions exist.

    I must be overlooking something laughably obvious.

    Any help or thoughts would be appreciated.

    Thank you,

    Brian

  • Shannon Deminick 1524 posts 5270 karma points MVP 2x
    Aug 13, 2020 @ 08:38
    Shannon Deminick
    100

    The error:

    Compiler Error Message: CS0246: The type or namespace name 'IPublishedContent' could not be found (are you missing a using directive or an assembly reference?)
    

    means you are missing a @using statement like

    @using Umbraco.Core.Models.PublishedContent;
    
  • Brian 30 posts 171 karma points
    Aug 13, 2020 @ 13:54
    Brian
    0

    Thank you, Shannon. The images are working now.

    I knew it was something painfully obvious.

    Take care,

    Brian

Please Sign in or register to post replies

Write your reply to:

Draft