Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jesper Lysgaard 16 posts 76 karma points
    Aug 06, 2015 @ 12:40
    Jesper Lysgaard
    0

    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:

    @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

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Aug 06, 2015 @ 12:57
    Dennis Aaen
    100

    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

  • Jesper Lysgaard 16 posts 76 karma points
    Aug 06, 2015 @ 13:11
    Jesper Lysgaard
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft