Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 886 posts 2415 karma points
    Sep 19, 2014 @ 22:33
    Claushingebjerg
    0

    get url from node ID

    Is this an acceptable way to get an url for a page, or is there a better way?

    <a href="@Umbraco.NiceUrl(@fieldset.GetValue("link").AsInt())">  click</a>
    
    ("link" is a content picker in an archetype)
  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Sep 19, 2014 @ 22:38
    Jeavon Leopold
    1

    Yes, perhaps a slight tweak:

    <a href="@Umbraco.NiceUrl(fieldset.GetValue<int>("link"))">click</a>
    
  • Claushingebjerg 886 posts 2415 karma points
    Sep 22, 2014 @ 15:23
    Claushingebjerg
    0

    Nice!

    So what if i'm inside an ipublished context?

    @Umbraco.NiceUrl(@boxItem.GetProperty<int>("link").Value)
    or
    @Umbraco.NiceUrl(@boxItem.GetProperty("link").Value.AsInt())

    Doesnt really work...

    @boxItem.GetProperty("link").Value

    Gives me the id correctly, but as a string i guess.

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Sep 22, 2014 @ 15:24
    Jeavon Leopold
    100

    Simply:

    @Umbraco.NiceUrl(boxItem.GetPropertyValue<int>("link"))
    

    Should always use GetPropertyValue rather than GetProperty in Razor rendering

  • Claushingebjerg 886 posts 2415 karma points
    Sep 22, 2014 @ 15:28
    Claushingebjerg
    0

    Holy s... that was fast. And precise, and clean :)

    Thanks!

     

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Sep 22, 2014 @ 15:50
    Jeavon Leopold
    0

    np :)

  • 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.

Please Sign in or register to post replies