Display images from "Image Media Picker"

307 views Asked by At

I am not new to programming but I am new to Umbraco/.Net 7

I am trying to create my own blog using Umbraco 11 and I was following the Youtube videos from "Umbraco Learning Base" (https://www.youtube.com/watch?v=xMS-rtqhWzU) timestamp 7:12 but I when I run the exact same code It does not work.

This is the code I have

<section id="@Model.Value("announcementTite")" class="about">
  <div class="container" data-aos="fade-up">

    <div class="section-header">
      <h2>@Model.Value("announcementTite")</h2>
      <p>@Model.Value("announcementSubTite")</p>
    </div>

    <div class="row gy-12">
      <div class="col-lg-12">
        @{
            var selection = Umbraco.Content(Guid.Parse("9e024bfc-fd9d-40fb-b07d-7731d49b244a"))
            .ChildrenOfType("announcementDetails")
            .Where(x => x.IsVisible());
        }
        <ul>
            @foreach (var item in selection)
            {
                var thumbnail = item.Value<IPublishedContent>("announcementDetailImage");
                <li>
                    <div class="thumbnail-img" style="background-image:url('#')"></div>
                    <a href="@item.Url()">@item.Name()</a>
                    
                    --- 
                    @thumbnail

        
                </li>
            }
        </ul>

      </div>
    </div>
  </div>
</section><!-- End Section -->

This is the value i get from the variable thumbnail

Umbraco.Cms.Core.Models.MediaWithCrops`1[Umbraco.Cms.Web.Common.PublishedModels.Image]

If I add @thumbnail.Url() to the thumbnail I get the following error:

System.NullReferenceException: 'Object reference not set to an instance of an object.'

If anyone can point me to how to move forward I would be really apricate it

1

There are 1 answers

0
Nurhak Kaya On

I'd recommend you to take a look at some more recent videos, like Paul Seal's videos about how to develop a v10 website to learn more about Umbraco CMS.

That Umbraco example is for an Umbraco v9.2.0 (.NET 5.0) website. Latest version of Umbraco is v11.2.0 that is running on .NET 7.

It is possible that some of the Issue #12349 changes might have caused some of your problems (this is the only change that I can see that might have caused some problems). The other options is that you haven't created your ModelsBuilder models. You might want to check that.

In any case, look at Paul's videos as things are very similar for v10 and v11 and you shouldn't create any v9 Umbraco projects any longer as it is already out-of-date.

enter image description here