Copied to clipboard

Flag this post as spam?

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


  • rkae 6 posts 85 karma points
    Aug 24, 2017 @ 15:12
    rkae
    0

    How to use media picker with doc type grid editor?

    Hello,

    i try to use a doc type with a media picker property in a grid. My Template:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    
    @{
        var typedMediaPickerSingle = Model.Content.GetPropertyValue<IPublishedContent>("image");
        if (typedMediaPickerSingle != null)
        {
            <p>@typedMediaPickerSingle.Url</p>
            <img src="@typedMediaPickerSingle.Url" style="width:200px" alt="@typedMediaPickerSingle.GetPropertyValue("alt")" />
        }
    }  
    

    This results in an exception, that 'Umbraco.Core.Models.IPublishedContent' does not contain no definition for 'Content'. How do i use it right? Thanks

  • Marc Goodson 2157 posts 14434 karma points MVP 9x c-trib
    Aug 27, 2017 @ 21:32
    Marc Goodson
    100

    Hi rkae

    I think because you are inheriting UmbracoViewPage, you do not have a Content property representing an IPublishedContent instance on your model.

    Have a look at this answer to explain the difference between UmbracoViewPage and UmbracoTemplatePage

    https://our.umbraco.org/forum/developers/api-questions/52597-What-is-the-difference-between-UmbracoViewPage-and-UmbracoTemplatePage

    So

     var typedMediaPickerSingle = Model.GetPropertyValue<IPublishedContent>("image");
    

    should work

  • rkae 6 posts 85 karma points
    Aug 28, 2017 @ 07:41
    rkae
    0

    You are correct, thank you!

  • 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