Copied to clipboard

Flag this post as spam?

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


  • Niklas Hjelm 104 posts 125 karma points
    Jun 01, 2011 @ 22:01
    Niklas Hjelm
    0

    Niceurl for contentpicker property

    Simple question. How do I get the niceurl from a property (contentpicker)

    <a href='@Model.mylinkproperty'>Test</a>

    This only gets me the id. Tried a couple of versions but cannot seem to find the right one. 

    Help please :)

    / Niklas

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jun 01, 2011 @ 22:21
    Tom Fulton
    2

    Hi Niklas,

    Try using the NiceUrl function.  I know nothing about Razor but believe it would be:

    <a href="@umbraco.library.NiceUrl(Model.Id)">Test</a>

    -Tom

  • Anthony Candaele 1197 posts 2049 karma points
    May 25, 2012 @ 14:15
    Anthony Candaele
    0

    Hi Tom,

    I try to implement this in this Razor code:

    var disclaimerpage = umbraco.library.NiceUrl(Model.Parent.siteDisclaimerPage);

    But when I run the code, I get an error on this line with the error message:

    "The best overloaded method match for 'umbraco.library.NiceUrl(int)' has some invalid arguments"

    There is an argument issue because the property 'siteDisclaimerPage' is of type string (an id from selecting a page with the Content Picker)

    greetings,

    Anthony

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    May 25, 2012 @ 14:20
    Tom Fulton
    1

    Hi Anthony,

    Try something like this instead:

    var disclaimerPage = Library.NodeById(Model.Parent.siteDisclaimerPage);
    <a href="@disclaimerPage.Url">@disclaimerPage.Name</a>

    Otherwise you can convert the string to int and use NiceUrl but this might be better.

    -Tom

  • Anthony Candaele 1197 posts 2049 karma points
    May 25, 2012 @ 14:25
    Anthony Candaele
    0

    Oh I see,

    I found this solution to work:

    @{

        var disclaimerpage = Library.NodeById(Model.Parent.siteDisclaimerPage);

        var url = umbraco.library.NiceUrl(disclaimerpage.Id);

    }

    I'll try yours also, because it's one line of code less :)

    Anthony

  • Anthony Candaele 1197 posts 2049 karma points
    May 25, 2012 @ 14:30
    Anthony Candaele
    0

    yep, your suggestion also works. I'll take your code, as it's one line of code less and one variable (= memory allocation) less.

    Thanks,

    Anthony

Please Sign in or register to post replies

Write your reply to:

Draft