Copied to clipboard

Flag this post as spam?

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


  • Trent Grandey 22 posts 143 karma points
    May 28, 2017 @ 20:13
    Trent Grandey
    0

    Archetype MediaPicker Udi

    I am starting a new site using Umbraco version 7.6.1 assembly: 1.0.6337.40631.

    I'm using Archetype as I have in a dozen other sites. I am using @Html.RenderArchetypePartials(Model.Content.GetPropertyValue

    I've tried casting the object to a number of different things with no luck.

    If I put a MediaPicker on my Document Type directly, I can see that the data is stored the same, but the base property converters work correctly and the usual Umbraco.Field("photo") returns the Id.

    Here's how the data is stored: Archetype: {"alias":"photo","value":"umb://media/1912ece0d5954e6891147e712d24ba69"} Doc Type Property: ImageTest: umb://media/48e3a7837af44134a93e8d90141ece74

    Is there a way to retrieve this from an Archetype? Am I missing something simple?

    Thanks,

    Trent

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    May 28, 2017 @ 21:57
    Alex Skrypnyk
    1

    Hi Trent

    Try to use this code:

    var mediaItems =  Model.GetValue<IEnumerable<IPublishedContent>>("photo");
    

    "Umbraco.Core.Udi[]" is a type of unified ids that are using in Core with Property Value Converters for getting all data directly from entities.

    Thanks,

    Alex

  • Trent Grandey 22 posts 143 karma points
    May 29, 2017 @ 03:46
    Trent Grandey
    0

    Thank you, Alex.

    I tried so many things, I'm not sure which one did it, but it all the sudden started returning the media id as expected. I reinstalled everything from nuget and i'm assuming that did it. Obviously one of the type converters wasn't working correctly for some reason.

    But I do appreciate your reply!

    Trent

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    May 29, 2017 @ 10:17
    Alex Skrypnyk
    0

    You are welcome, Trent.

    Ids or UDI settings defined in config option in umbracoSettings.config

    Did you read breaking changes in 7.6 version? - https://our.umbraco.org/documentation/Getting-Started/Setup/Upgrading/760-breaking-changes#property-editors-storing-udi-instead-of-id-u4-9310

    Alex

  • Trent Grandey 22 posts 143 karma points
    May 30, 2017 @ 14:06
    Trent Grandey
    1

    I had read that. And I will be looking out for those changes as I update my current sites. This site that I was struggling with was a brand new site and my first one that started with 7.6 Umbraco. I did notice in the definitions that the property editor name was MediaPicker2. I'm guessing that's the new one mentioned in the article.

    I was used to Model.GetValue(xxx) returning the ID of the media. As I circled back to this yesterday, I finally started a new Document Type to start from scratch. I did finally get this to work as intended using your suggestion of using the generic to cast it to IPublishedContent. Model.GetValue

    I am anxious to see how the upgrade works and affects some of my current sites. I guess that's my next task. But your help certainly got me over the hump on this one.

    Much appreciated!

    Trent

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    May 30, 2017 @ 14:27
    Alex Skrypnyk
    0

    Hi Trent

    You are welcome, really enjoy talking with Umbraco developers. Ask more if something.

    Cheers,

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft