I am trying to implement a slider and have gotten almost to the finish line but i have a major issue that i cant get past.
When trying to get the image from Umbraco using the Umbraco.Media() method i get nothing back.
Here is the code:
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{
//get all children of type 'slide_item
var slideId = Model.MacroParameters["sliderId"];
var node = Umbraco.Content(slideId);
var slides = node.Children.Where("DocumentTypeAlias == \"slide_item\"");
}
<div class="slider">
@foreach (var slide in @slides) {
//Fallback: Ignore slide when no image was uploaded,
//else the slide would cause a server error.
if(@slide.slideImage != null) {
var image = Umbraco.Media(@slide.slideImage);
<div class="slide">
<img alt="@slide.name" src="@image.Url">
</div>
}
}
</div>
For some reason the var image = Umbraco.Media(@slide.slideImage); call does not return anything so all i get right now is the alt text.
I can print @slide.slideImage and see the configured id printed, so the image exists and the id is there.
Cant retrieve Umbraco.Media in macro code
Hello.
I am trying to implement a slider and have gotten almost to the finish line but i have a major issue that i cant get past.
When trying to get the image from Umbraco using the Umbraco.Media() method i get nothing back.
Here is the code:
For some reason the var image = Umbraco.Media(@slide.slideImage); call does not return anything so all i get right now is the alt text.
I can print @slide.slideImage and see the configured id printed, so the image exists and the id is there.
Any idea of what can be the problem?
If I use GetType on the slide.slideImage umbraco tells me: Umbraco.Web.PublishedContentModels.Image
So you should try
or you could use
Hi Mikael
What version of Umbraco are you using?
Are Property value converters enabled? If yes, then use code that Elitenet provided.
Thanks,
Alex
I found the .toString() solution after posting but forgot to update the post. Problem solved.
Glad that you solved the issue!
is working on a reply...