The image type I am using is they "Image Media Picker (Umbraco.MediaPicker3)
I already have @using Umbraco.Extensions in my "_viewImports.cshtml" file which should be included on all pages (correct?)
If I try
@{
var typedMultiMediaPicker = Model.Value<IEnumerable<MediaWithCrops>>("image");
foreach (var entry in typedMultiMediaPicker)
{
<img src="@entry.MediaUrl()" style="width:200px" />
}
}
Visual Studio does not like "MediaWithCrops" saying "The type or namespace name 'MediaWithCrops' could not be found (are you missing a using directive or an assembly reference?)"
How do I Render Images an image on the page
When I use the Insert Value option on the templates area I get
Which renders
Umbraco.Cms.Core.Models.MediaWithCrops`1[Umbraco.Cms.Web.Common.PublishedModels.Image]
How do I convert it to the Image Path so I can add it inside the proper HTML?
Hi,
@Model.Value<MediaWithCrops>("image").Url()
should do itMore information here - https://docs.umbraco.com/umbraco-cms/v/10.latest-lts/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/media-picker-3
This is what I get when I try that.
Argument 1: cannot convert from 'method group' to 'object?'
Hi Yaco
This syntax keeps changing between the versions, but I think now it would be
There are some examples here...
https://docs.umbraco.com/umbraco-cms/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/media-picker-3#mvc-view-example
regards
Marc
I still get the same error.
This is all the code on the page
I downloaded the cheat sheet and will study it to become more familiar with it.
I see the VS is telling me the following error but not sure why.
P.S I do have Modelsbuilder enable
Hi Yaco
What type of property editor is your 'image' property??
Is it a single MediaPicker3 or can the editor pick more than one Media Item?
if it was multiple then you'd have to do something like this
But with multiple not allowed, I think it would be this
@using Umbraco.Cms.Core.Models @{ var typedMediaPickerSingle = Model.Value
You might need to have
at the top of your view to access the MediaUrl() method as I think it's an extension method.
https://github.com/umbraco/Umbraco-CMS/blob/36069aa8139b6125398786d378ac712b5382d0b0/src/Umbraco.Core/Extensions/PublishedElementExtensions.cs#L274
regards
marc
Still stuck...
The image type I am using is they "Image Media Picker (Umbraco.MediaPicker3)
I already have @using Umbraco.Extensions in my "_viewImports.cshtml" file which should be included on all pages (correct?)
If I try
Visual Studio does not like "MediaWithCrops" saying "The type or namespace name 'MediaWithCrops' could not be found (are you missing a using directive or an assembly reference?)"
Hi Yaco
That would suggest it's missing the namespace
which is where MediaWithCrops lives.
regards
Marc
Just in case anyone else has the same issue.
This is what ended up working for me (Multiple disabled with Modelsbuilder)
Why use all the extra code when
would do?
Just for info this can be cut down to just this line of code
<img src="@Model.MEDIA-NAME-HERE.MediaUrl()" style="width:200px" />
is working on a reply...