I want to use a simple Media Picker with the name of "MediaPick" to load an image into a page using Razor.
The only URL I retrieve from Razor is the URL (href="1219"). This of course doesn't show an image but an error. What change do I have make in my Razor script to get the FULL URL like 'media/photos/1219/image.jpg'?
Below my code:
@{ var parent = @Model.AncestorOrSelf(3); var refNodes = parent.Children.Where("Visible"); foreach (var item in refNodes){ <div class="span3"> <a class="group1" href="@item.afbeelding" title="@item.titel"> <img src="@item.mediaPick" /> </a> </div> } }
I already found a lot of XSLT solutions, but I really just want to create the same thing in Razor.
SImple Media Picker / Razor question
I want to use a simple Media Picker with the name of "MediaPick" to load an image into a page using Razor.
The only URL I retrieve from Razor is the URL (href="1219"). This of course doesn't show an image but an error.
What change do I have make in my Razor script to get the FULL URL like 'media/photos/1219/image.jpg'?
Below my code:
@{
var parent = @Model.AncestorOrSelf(3);
var refNodes = parent.Children.Where("Visible");
foreach (var item in refNodes){
<div class="span3">
<a class="group1" href="@item.afbeelding" title="@item.titel">
<img src="@item.mediaPick" />
</a>
</div>
}
}
I already found a lot of XSLT solutions, but I really just want to create the same thing in Razor.
Thanks in advance!
Hi Peter,
You get only the media item ID indeed. In order to gate the url, I think you need to use something like this:
You can find more help about this and other razor methods in the nice "razor cheat sheet" here : http://our.umbraco.org/projects/developer-tools/razor-dynamicnode-cheat-sheet
Hope this helps.
Cheers,
Michael.
Hi Michael,
Wow, that was quick! And exactly what I was looking for, thank you so much!
I downloaded the razor cheatsheet earlier, but unfortunately my knowledge about razor isn't enough to understand everything in it ;-)
Thanks again!
Hi Peter,
You're very welcome :-)
Cheers,
Michael.
Hi Michael,
One other way of doing this would be
I got it working this way.
//fuji
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.