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 apologize in advance - I'm a newbie to Umbraco.
I have a header composition to add a jumbotron for each page.
I can get the title and subtitle to render, but the background image won't render.
In the composition, title and subtitle are both rich text editors. The header image is an image media picker.
My header is in a partial view, and the code looks like this:
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage <header class="masthead jumbotron text-center jumbotron-fluid" style="background-image: url("@Model.Value("headerImage")")"> <div class="container position-relative px-4 px-lg-5"> <div class="row gx-4 gx-lg-5 justify-content-center"> <div class="col-md-10 col-lg-8 col-xl-7"> <div class="container"> <h1 class="display-1">@Model.Value("title", fallback: Fallback.ToAncestors)</h1> <p>@Model.Value("subTitle", fallback: Fallback.ToAncestors)</p> </div> </div> </div> </div> </header>
When I Inspect the code - this is what the @Model.Value is rendering.
url('Umbraco.Cms.Core.Models.MediaWithCrops`1[Umbraco.Cms.Web.Common.PublishedModels.Image]')
Any assistance would be greatly appreciated.
Hi Cedeste,
try doing it this way url(@Model.Value<MediaWithCrops>("headerImage").Url())
url(@Model.Value<MediaWithCrops>("headerImage").Url())
Thank you.
But that doesn't work; I get the following error:
Argument 3: cannot convert from 'method group' to 'object?'
Any advice?
could be the way you are using it in the style declartion because of the nested quotes, I would do it this way, it should work fine
@{ var bImage = Model.Value<MediaWithCrops>("headerImage").Url(); } <header class="masthead jumbotron text-center jumbotron-fluid" style="background-image: url('@bImage')">
That didn't work, either.
The type or namespace name 'MediaWithCrops' could not be found (are you missing a using directive or an assembly reference?)
I'm using Umbraco 11 - not sure if that makes a difference.
you need to have this at the top of your View page
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage @using Umbraco.Cms.Core.Models
THAT WORKED!! THANK YOU!
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
@ModelValue not rendering background images
I apologize in advance - I'm a newbie to Umbraco.
I have a header composition to add a jumbotron for each page.
I can get the title and subtitle to render, but the background image won't render.
In the composition, title and subtitle are both rich text editors. The header image is an image media picker.
My header is in a partial view, and the code looks like this:
When I Inspect the code - this is what the @Model.Value is rendering.
Any assistance would be greatly appreciated.
Hi Cedeste,
try doing it this way
url(@Model.Value<MediaWithCrops>("headerImage").Url())
Thank you.
But that doesn't work; I get the following error:
Argument 3: cannot convert from 'method group' to 'object?'
Any advice?
could be the way you are using it in the style declartion because of the nested quotes, I would do it this way, it should work fine
That didn't work, either.
The type or namespace name 'MediaWithCrops' could not be found (are you missing a using directive or an assembly reference?)
I'm using Umbraco 11 - not sure if that makes a difference.
you need to have this at the top of your View page
THAT WORKED!! THANK YOU!
is working on a reply...