英文:
Display images from "Image Media Picker"
问题
以下是你要翻译的内容:
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
英文:
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
得分: 1
我建议你查看一些更新的视频,比如Paul Seal关于如何开发v10网站的视频,以了解有关Umbraco CMS的更多信息。
这个Umbraco示例是针对Umbraco v9.2.0 (.NET 5.0)网站的。 Umbraco的最新版本是v11.2.0,它运行在.NET 7上。
有可能一些Issue #12349的更改可能导致了一些问题(这是我能看到可能引起问题的唯一更改)。另一个选项是你可能还没有创建ModelsBuilder模型。你可能要检查一下。
无论如何,查看Paul的视频,因为v10和v11的情况非常相似,你不应该再创建任何v9的Umbraco项目,因为它已经过时了。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论