我使用构图创建了横幅。图片在博客页面中收到了空值,但在其他页面中可用。
横幅局部视图
@{
var site = Model.Root();
var bannerImage = Model.Value<IPublishedContent>("bannerImage");
}
@if (bannerImage != null)
{
<section class="banner">
<div class="card bg-dark border-0 text-center">
<img class="card-img rounded-0 img-fluid" src="@bannerImage.Url" alt="Card image">
<div class="card-img-overlay h-100 d-flex flex-column justify-content-center">
<h1 class="card-title"> @Model.Value("bannerTitle")</h1>
<p class="card-text"> @Model.Value("bannerContent")</p>
</div>
</div>
</section>
}
博客页面
@using ContentModels = Umbraco.Web.PublishedModels;
@inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.Blog>
@using Umbraco.Web;
@{
Layout = "master.cshtml";
}
@Html.Partial("~/Views/Partials/Shared/Banner.cshtml")