Copied to clipboard

Flag this post as spam?

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


  • Giorgi 5 posts 75 karma points
    Jul 08, 2019 @ 13:25
    Giorgi
    0

    Can't get image or image url from published content

    Hello Friends, i'm trying to get image or image url from already published content (like blogpost)

    i have Media Picker called "image", uploaded image file in content and

    1. tried @Model.image.url but getting error
    2. tried @Model.Value("image").Url but getting error

    enter image description here enter image description here

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jul 08, 2019 @ 15:02
    Alex Skrypnyk
    0

    Hi Giorgi

    Looks like the "Model" object in your view is not the right. Can you show the whole view code?

    Thanks,

    Alex

  • Giorgi 5 posts 75 karma points
    Jul 08, 2019 @ 15:59
    Giorgi
    0
    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.Service>
    @using ContentModels = Umbraco.Web.PublishedModels;
    @{
        Layout = "master.cshtml";
    }
    
    
    
    @Model.image.Url
    
  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jul 08, 2019 @ 16:54
    Alex Skrypnyk
    0

    is "Service" your doctype alias?

  • Giorgi 5 posts 75 karma points
    Jul 08, 2019 @ 17:07
    Giorgi
    0

    yes sure. :(

    enter image description here

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 08, 2019 @ 17:10
    Dennis Aaen
    0

    Hi Giorgi,

    Have a look at the media picker documentation here on how to get the image to be printed out.

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

    Hope this helps,

    /Dennis

  • Giorgi 5 posts 75 karma points
    Jul 08, 2019 @ 17:41
    Giorgi
    0

    This works for me but there are too many lines for only 1 image or image url :/ , is there any other solutions?

    @{
    var typedMediaPickerSingle = Model.Value<IPublishedContent>("image");
    
    if (typedMediaPickerSingle != null)
    {
    
        <p>@typedMediaPickerSingle.Url</p>
        <img src="@typedMediaPickerSingle.Url" style="width:200px" />
    }
    

    }

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 08, 2019 @ 19:00
    Dennis Aaen
    0

    Hi Giorgi,

    Of course, we can do it a bit simpler

    @{
    
        if (Model.Value<IPublishedContent>("featuredBanner") != null)
        {
            <p>@Model.Value<IPublishedContent>("featuredBanner").Url</p>
            <img src='@Model.Value<IPublishedContent>("featuredBanner").Url' />
        }
    }
    

    )f I was you then I will make that extra variable so you don't have to write Model.Value

    All the best,

    /Dennis

  • Giorgi 5 posts 75 karma points
    Jul 09, 2019 @ 13:34
    Giorgi
    0

    how to make it as extra variable? what do you mean?

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jul 09, 2019 @ 14:29
    Alex Skrypnyk
    0

    Hi Giorgi

    I think Dennis wanted to say that code with extra variable looks better and more efficient, like this:

    @{
        var featuredBanner = Model.Value<IPublishedContent>("featuredBanner");
        if (featuredBanner != null)
        {
            <p>@featuredBanner.Url</p>
            <img src='@featuredBanner.Url' />
        }
    }
    
  • Jonathan Distenfeld 105 posts 618 karma points
    Jul 09, 2019 @ 06:29
    Jonathan Distenfeld
    0

    Hi Giorgi,

    have you tried reloading/generating your models in Umbraco backoffice? Maybe after generating, double check if your service model has the "image" property.

    ~Jonathan

Please Sign in or register to post replies

Write your reply to:

Draft