Copied to clipboard

Flag this post as spam?

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


  • Taymar 9 posts 29 karma points
    Jun 19, 2012 @ 03:10
    Taymar
    0

    NiceUrl & invalid arguments with content picker on ancestor node

    I've searched around and gone through many examples but I still can't get this to work.

    I have a content picker on my homepage, called onlineLink. I want to have a macro I can drop anywhere in the site and have it link to the page selected in onlineLink. When I test the value of my variable, it seems to return it correctly on screen, but no matter which syntax I've tried for NiceUrl it won't display. The trace says The best overloaded method match for 'umbraco.library.NiceUrl(int)' has some invalid arguments

    Here's my code:

    @{
      var myLink @Model.AncestorOrSelf().GetProperty("onlineLink");

      <span>Node@myLink.Value</span<!-this displays the node id correctly -->
      <class="onlineWidget" href="@umbraco.library.NiceUrl(@myLink)"></a>
        
    }

     

  • Nigel Wilson 945 posts 2077 karma points
    Jun 19, 2012 @ 03:19
    Nigel Wilson
    0

    Hi Taymar

    I am not well versed in razor but wonder if it is worth trying to convert the value to an integer before trying to create the link, e.g.

    int myLink = Convert.ToInt32(@Model.AncestorOrSelf().GetProperty("onlineLink"));

    Cheers

    Nigel

     

  • Taymar 9 posts 29 karma points
    Jun 19, 2012 @ 03:30
    Taymar
    0

    Thanks very much Nigel,

    I've tried this change and I get a different error now - Unable to cast object of type 'umbraco.MacroEngines.PropertyResult' to type 'System.IConvertible'. at System.Convert.ToInt32(Object value)

    The only line of code above my main codeblock is : @inherits umbraco.MacroEngines.DynamicNodeContext

    Should I be using any other libraries?



  • Nigel Wilson 945 posts 2077 karma points
    Jun 19, 2012 @ 04:13
    Nigel Wilson
    0

    Hey - maybe this

    int myLink =Convert.ToInt32(@Model.AncestorOrSelf().GetProperty("onlineLink").ToString());

    Hopefully someone with more intimate razor knowledge can advise a more accurate solution than me guessing at things...

    Hope you get it sorted.

    Cheers

    Nigel

  • Douglas Ludlow 210 posts 366 karma points
    Jun 19, 2012 @ 06:22
    Douglas Ludlow
    0

    You'll need to convert the value, not the property:

    @{
    int myLink = Convert.ToInt32(Model.AncestorOrSelf().GetProperty("onlineLink").Value);
    <a class="onlineWidget" href="@umbraco.library.NiceUrl(@myLink)"></a>
    }

    This will also work:

    @{
    int myLink = Convert.ToInt32(Model.AncestorOrSelf().onlineLink);
    <a class="onlineWidget" href="@umbraco.library.NiceUrl(@myLink)"></a>
    }

    Or this:

    @{
    int myLink = Convert.ToInt32(Model._onlineLink);
    <a class="onlineWidget" href="@umbraco.library.NiceUrl(@myLink)"></a>
    }

    Or even this:

    @{
    dynamic myNode = Library.NodeById(Model._onlineLink);
    <a class="onlineWidget" href="@myNode.Url"></a>
    }

    The possibilities are endless!

  • Taymar 9 posts 29 karma points
    Jun 19, 2012 @ 13:01
    Taymar
    0

    Thank you so much guys, this had me stumped for hours.

Please Sign in or register to post replies

Write your reply to:

Draft