Copied to clipboard

Flag this post as spam?

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


  • Bunnynut 136 posts 318 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 441 posts 1884 karma points MVP 2x 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 136 posts 318 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 481 posts 1413 karma points MVP 7x c-trib
    Sep 03, 2019 @ 15:21
    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 151 posts 1024 karma points MVP c-trib
    Sep 03, 2019 @ 15:58
    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 481 posts 1413 karma points MVP 7x c-trib
    Sep 04, 2019 @ 12:32
    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 66 karma points
    Sep 03, 2019 @ 16:17
    giuseppe
    1

    I had the same problem and solved in this way

    @{
        var foto = Model.Value<IPublishedContent>("foto");
    }
    <img src="@foto.Url" />
    
  • Tarik 196 posts 840 karma points c-trib
    Sep 06, 2019 @ 08:34
    Tarik
    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