Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 939 posts 2574 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 3074 posts 13631 karma points MVP 11x 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 939 posts 2574 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 3074 posts 13631 karma points MVP 11x 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 939 posts 2574 karma points
    Sep 22, 2014 @ 15:28
    Claushingebjerg
    0

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

    Thanks!

     

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Sep 22, 2014 @ 15:50
    Jeavon Leopold
    0

    np :)

Please Sign in or register to post replies

Write your reply to:

Draft