Copied to clipboard

Flag this post as spam?

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


  • Matt 308 posts 730 karma points
    Jul 02, 2019 @ 07:07
    Matt
    0

    Umbraco 8 Media picker

    Hello,

    I've moving a small website over manually from umbraco 7 to 8 and having issues with media picker.

    Here was my code in umbraco 7 which doesnt seem to work now in 8.

                <a href="@item.Url">
    
                    @{
                        var blogImage = item.GetPropertyValue<IPublishedContent>("blogImage");
                        if (blogImage != null)
                        {
                            <img src="@blogImage.Url" height="300" width="374" srcset="" class="blog-image">
                        }
                    }
                </a>
    

    I've now changed it to the following and it still doesn't display any images, I get no errors.

                <a href="@item.Url">
    
                    @{
                        var blogImage = Model.Value<IPublishedContent>("blogImage");
                        if (blogImage != null)
                        {
                            <img src="@blogImage.Url" height="300" width="374" srcset="" class="blog-image">
                        }
                    }
                </a>
    

    Thanks

  • Jonathan Distenfeld 105 posts 618 karma points
    Jul 02, 2019 @ 07:40
    Jonathan Distenfeld
    0

    Hi Matt,

    not sure if this might be a typo but shouldn't it be item.Value<IPublishedContent>("blobImage") instead of Model.Value...?

    ~ Jonathan

  • Matt 308 posts 730 karma points
    Jul 02, 2019 @ 07:50
    Matt
    0

    Hello Jonathan,

    Thanks for that, that worked a treat.

    No wasn't a typo, I was just using this code as a guide;

    https://our.umbraco.com/documentation/Getting-Started/Backoffice/Property-Editors/Built-in-Property-Editors/Media-Picker/

    Whats the difference in me using Item or Model?

    Thanks

  • Jonathan Distenfeld 105 posts 618 karma points
    Jul 02, 2019 @ 08:10
    Jonathan Distenfeld
    0

    Hi Matt,

    glad to here it's working!

    The item you are using must be a variable you are declaring somewhere above. Check for a line like this: var item = ...

    The Model is the object that get's passed into your view and holds the data you want to display. In case of Umbraco, it's usually an IPublishedContent wrapping the data of your content node.

    If you wan't to know more about how MVC and Razor works check these Links:

    https://www.tutorialsteacher.com/mvc/mvc-architecture

    https://www.tutorialsteacher.com/mvc/razor-syntax

    For more information about how Umbraco works with Razor take a look at this:

    https://our.umbraco.com/documentation/Reference/Templating/Mvc/views

    https://our.umbraco.com/documentation/Reference/Querying/IPublishedContent/

    ~ Jonathan

  • Nurhak Kaya 40 posts 133 karma points
    May 06, 2020 @ 13:33
    Nurhak Kaya
    0

    Just a note for future reference: there will be problems with certain properties due to them being obsolete, see quick notes below, and for more details please take a look at here;

    If you are upgrading an old website, check if you are using obsolete properties in your Data Types and change them to their updated counterparts. The migration will fail if you are still using obsolete properties!

    The updated properties are:

    Content Picker Media Picker Member Picker Multinode Treepicker Nested Content Folder Browser Related Links You can see if your site is using the obsolete properties by the (Obsolete) prefix in their name.

Please Sign in or register to post replies

Write your reply to:

Draft