简体   繁体   中英

Umbraco 8 render image from IPublishedContent

I am using Umbraco 8 for the first time and being tripped up a lot vs Umbraco 6/7.

So I am trying to render some images in the _Layout partial view. From a list of items in the root. Document type below.

在此处输入图像描述

I used the Query builder in the _Layout.cshtml to end up with the following to iterate over the logos.

@{
var selection = Umbraco.Content(Guid.Parse("92c903b5-4772-48d5-8e16-5238e45c1e36"))
.ChildrenOfType("footerLogo")
.Where(x => x.IsVisible());
}
<ul>
    @foreach (var item in selection)
    {
    <li>
        <a href="@item.Url">@item.Name</a>


// I added this code and put a breakpoint in VS2019 to inspect the object
       @item
// Using the immediate window, this gave me a full object
       @item.GetProperty("Logo").GetValue()

在此处输入图像描述

I've tried to access the Url property with

 item.GetProperty("Logo").GetValue().Url

but getting exception

 cannot convert from 'method group' to 'HelperResult'

I've spent a couple of hours on googling Umbraco 8 image rendering but no luck. Just wondering if someone could give me a pointer on how to get at these values?

Many Thanks Rob

This is untested but maybe you can try the following:

item.Value("Logo").url()

or

item.Url

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM