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
Hello Friends, i'm trying to get image or image url from already published content (like blogpost)
i have Media Picker called "image", uploaded image file in content and
Hi Giorgi
Looks like the "Model" object in your view is not the right. Can you show the whole view code?
Thanks,
Alex
@inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.Service> @using ContentModels = Umbraco.Web.PublishedModels; @{ Layout = "master.cshtml"; } @Model.image.Url
is "Service" your doctype alias?
yes sure. :(
Hi Giorgi,
Have a look at the media picker documentation here on how to get the image to be printed out.
https://our.umbraco.com/documentation/Getting-Started/Backoffice/Property-Editors/Built-in-Property-Editors/Media-Picker/
Hope this helps,
/Dennis
This works for me but there are too many lines for only 1 image or image url :/ , is there any other solutions?
@{ var typedMediaPickerSingle = Model.Value<IPublishedContent>("image"); if (typedMediaPickerSingle != null) { <p>@typedMediaPickerSingle.Url</p> <img src="@typedMediaPickerSingle.Url" style="width:200px" /> }
}
Of course, we can do it a bit simpler
@{ if (Model.Value<IPublishedContent>("featuredBanner") != null) { <p>@Model.Value<IPublishedContent>("featuredBanner").Url</p> <img src='@Model.Value<IPublishedContent>("featuredBanner").Url' /> } }
)f I was you then I will make that extra variable so you don't have to write Model.Value
All the best,
how to make it as extra variable? what do you mean?
I think Dennis wanted to say that code with extra variable looks better and more efficient, like this:
@{ var featuredBanner = Model.Value<IPublishedContent>("featuredBanner"); if (featuredBanner != null) { <p>@featuredBanner.Url</p> <img src='@featuredBanner.Url' /> } }
have you tried reloading/generating your models in Umbraco backoffice? Maybe after generating, double check if your service model has the "image" property.
~Jonathan
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Can't get image or image url from published content
Hello Friends, i'm trying to get image or image url from already published content (like blogpost)
i have Media Picker called "image", uploaded image file in content and
Hi Giorgi
Looks like the "Model" object in your view is not the right. Can you show the whole view code?
Thanks,
Alex
is "Service" your doctype alias?
yes sure. :(
Hi Giorgi,
Have a look at the media picker documentation here on how to get the image to be printed out.
https://our.umbraco.com/documentation/Getting-Started/Backoffice/Property-Editors/Built-in-Property-Editors/Media-Picker/
Hope this helps,
/Dennis
This works for me but there are too many lines for only 1 image or image url :/ , is there any other solutions?
}
Hi Giorgi,
Of course, we can do it a bit simpler
)f I was you then I will make that extra variable so you don't have to write Model.Value
All the best,
/Dennis
how to make it as extra variable? what do you mean?
Hi Giorgi
I think Dennis wanted to say that code with extra variable looks better and more efficient, like this:
Hi Giorgi,
have you tried reloading/generating your models in Umbraco backoffice? Maybe after generating, double check if your service model has the "image" property.
~Jonathan
is working on a reply...