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
Hi,
I am trying to get the url to a property with NIceUrl. The property is a Media Picker.
I am doing this in Razor:
@foreach (var realestate in item.Children) { <div> <p>@(Umbraco.NiceUrl(realestate .GetPropertyValue<int>("mainImage")))<br /></p> </div> <div><p>@(realestate .GetPropertyValue<string>("buildingYear"))</p> </div> <div><p>@realestate .Name</p> <br /><hr /><br /> </div> }
The property "buildingYear" and the Name is showing fine. The Id of the media item (image) is also available eg.: realestate .GetPropertyValue
The NiceUrl returns only a "/" or sometimes a # - which I know indicates an error.
What am I doing wrong here?
regards Jesper
Hi Jesper,
What if you do something like this, does this works for you.
@foreach (var realestate in item.Children) { <div> <p> @{ var mediaItem = Umbraco.TypedMedia(realestate.GetPropertyValue("mainImage")); <img src="@mediaItem.GetPropertyValue("umbracoFile")" alt="@mediaItem.GetPropertyValue("Name")"/> } <br /> </p> </div> <div><p>@(realestate .GetPropertyValue<string>("buildingYear"))</p> </div> <div><p>@realestate .Name</p> <br /><hr /><br /> </div> }
Hope this helps,
/Dennis
Hi Dennis,
Thank you very much. It works now - I also had to implement a check for if property is empty:
@{ if (realestate.GetPropertyValue("mainImage") != null) { .. }
I guess we took the level two course together? - You must have paid more attention to what Sebastiaan said ;-)
Keep up the good work.
/Jesper
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
NiceUrl returns nothing
Hi,
I am trying to get the url to a property with NIceUrl. The property is a Media Picker.
I am doing this in Razor:
The property "buildingYear" and the Name is showing fine. The Id of the media item (image) is also available eg.: realestate .GetPropertyValue
The NiceUrl returns only a "/" or sometimes a # - which I know indicates an error.
What am I doing wrong here?
regards Jesper
Hi Jesper,
What if you do something like this, does this works for you.
Hope this helps,
/Dennis
Hi Dennis,
Thank you very much. It works now - I also had to implement a check for if property is empty:
I guess we took the level two course together? - You must have paid more attention to what Sebastiaan said ;-)
Keep up the good work.
/Jesper
is working on a reply...