Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I created a banner using composition. Image received the null value in blog page but it works in other pages.
Banner Partial View
@{ 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> }
Blog page
@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")
Hi Sowndar
Which page do you have the 'bannerImage' defined on?
Homepage or every page?
If it's only on the site root homepage that the banner is picked then
var site = Model.Root(); var bannerImage = site.Value<IPublishedContent>("bannerImage");
should show the banner ok.
If it should be a different banner picked on every page then perhaps your blog page is missing the picker?
regards
marc
I created a compositions so I can inherit from compositions to all page.
Blog Content Page
Blog Document Type
I called in blog
I've just cut and paste what you have above into a new V8.0.0 site and it all 'just works'!!
The only thing that may be difference from your example above is the @inherits statement in the banner.cshtml partial; my full partial looks like this:
@using ContentModels = Umbraco.Web.PublishedModels; @inherits Umbraco.Web.Mvc.UmbracoViewPage @{ 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> }
if you have the exact same inherits, then it's weird maybe try saving your image again in the backoffice, or writing out the raw id value:
@Model.Value<string>("bannerImage")
to make sure something is picked!
Marc
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Composition media url is not working in blog page
I created a banner using composition. Image received the null value in blog page but it works in other pages.
Banner Partial View
Blog page
Hi Sowndar
Which page do you have the 'bannerImage' defined on?
Homepage or every page?
If it's only on the site root homepage that the banner is picked then
should show the banner ok.
If it should be a different banner picked on every page then perhaps your blog page is missing the picker?
regards
marc
I created a compositions so I can inherit from compositions to all page.
Blog Content Page
Blog Document Type
I called in blog
Hi Sowndar
I've just cut and paste what you have above into a new V8.0.0 site and it all 'just works'!!
The only thing that may be difference from your example above is the @inherits statement in the banner.cshtml partial; my full partial looks like this:
if you have the exact same inherits, then it's weird maybe try saving your image again in the backoffice, or writing out the raw id value:
to make sure something is picked!
regards
Marc
is working on a reply...