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 --> <a class="onlineWidget" href="@umbraco.library.NiceUrl(@myLink)"></a> }
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
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 -->
<a class="onlineWidget" href="@umbraco.library.NiceUrl(@myLink)"></a>
}
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.
Cheers
Nigel
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?
Hey - maybe this
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
You'll need to convert the value, not the property:
This will also work:
Or this:
Or even this:
The possibilities are endless!
Thank you so much guys, this had me stumped for hours.
is working on a reply...