显示来自“图像媒体选择器”的图像。

huangapple go评论61阅读模式
英文:

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

&lt;section id=&quot;@Model.Value(&quot;announcementTite&quot;)&quot; class=&quot;about&quot;&gt;
  &lt;div class=&quot;container&quot; data-aos=&quot;fade-up&quot;&gt;

    &lt;div class=&quot;section-header&quot;&gt;
      &lt;h2&gt;@Model.Value(&quot;announcementTite&quot;)&lt;/h2&gt;
      &lt;p&gt;@Model.Value(&quot;announcementSubTite&quot;)&lt;/p&gt;
    &lt;/div&gt;

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

        
        		&lt;/li&gt;
        	}
        &lt;/ul&gt;

      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;!-- End Section --&gt;

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.

显示来自“图像媒体选择器”的图像。

huangapple
  • 本文由 发表于 2023年3月7日 04:03:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75655341.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定