Copied to clipboard

Flag this post as spam?

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


  • Bunnynut 127 posts 309 karma points
    Jun 17, 2019 @ 17:45
    Bunnynut
    0

    Unable to show Image property in Umbraco 8

    I am trying get the url of an image property. @Model.Value("foto") only shows Umbraco.Web.PublishedModels.Image Does anybody know the correct way to do this?

  • Søren Gregersen 300 posts 1183 karma points MVP c-trib
    Jun 17, 2019 @ 20:18
    Søren Gregersen
    0

    Hi,

    The value is of the type you've written

    Your type (Umbraco.Web.PublishedModels.Image) should have and Url property that you can use

    @{
        var foto = Model.Value("foto");
    }
    <img src="@foto.Url" />
    

    Also, the page/view you are using this code on, could be changed to have the Umbraco.Web.PublishedModels.[PageType] as the model type ([PageType] being the actual type you are working with), then you could just write @Model.Foto.Url

    HTH

  • Bunnynut 127 posts 309 karma points
    Jun 23, 2019 @ 10:14
    Bunnynut
    0

    Thank you for your reply.

    When I use the code from your example I get the following exception message:

    Argument 1: cannot convert from 'method group' to 'object'
    
  • Owain Williams 374 posts 1115 karma points MVP 2x c-trib
    21 days ago
    Owain Williams
    0

    Did you find a solution for this - I've just ran in to the same error with a image.url

    Thanks,

  • Steve Megson 48 posts 320 karma points c-trib
    21 days ago
    Steve Megson
    0

    Url is a method rather than a property, so you need @image.Url().

  • Liam Jones 1 post 71 karma points
    Jun 29, 2019 @ 20:15
    Liam Jones
    0

    Having this exact same thing. Would appreciate some kind of guidance on this.

  • Owain Williams 374 posts 1115 karma points MVP 2x c-trib
    20 days ago
    Owain Williams
    0

    I did the following:

    This is what I had:

     @if (siteSettings.SmallLogo != null && siteSettings.SmallLogoLink != null)
                        {
                                <li>
                                    <a href="@siteSettings.SmallLogoLink.Url" target="@siteSettings.SmallLogoLink.Target"><img src="@siteSettings.SmallLogo.Url" /></a>
                                </li>
    
                        }
    

    and it didn't work so I changed my code to:

    @if (siteSettings.SmallLogo != null && siteSettings.SmallLogoLink != null)
                        {
                            foreach (var link in siteSettings.SmallLogoLink)
                            {
                                <li>
                                    <a href="@link.Url" target="@link.Target"><img src="@siteSettings.SmallLogo.Url" /></a>
                                </li>
                            }
    
                        }
    

    This now works. Hope it helps.

  • giuseppe 9 posts 63 karma points
    21 days ago
    giuseppe
    1

    I had the same problem and solved in this way

    @{
        var foto = Model.Value<IPublishedContent>("foto");
    }
    <img src="@foto.Url" />
    
  • Abuabdellah | Biker | Umbracian | Freelancer | PPH.me/abuabdellah
    0

    There is a similar post subject answered the issue.

    @{
       string imageUrl = Model.Value<IPublishedContent>("siteLogo") !=  null ? Model.Value<IPublishedContent>("siteLogo").Url : "";
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft