Copied to clipboard

Flag this post as spam?

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


  • Pancheri Damien 16 posts 35 karma points
    Mar 22, 2013 @ 10:12
    Pancheri Damien
    0

    Umbraco 6.0.2 Get Url from node ID

    Hi all,

    I'm trying to get the url from a node from a content picker.

    This code works fine:

    @foreach(var item in Model.SiteSettings.First().HomepageBlockOuts.First().Children)
    {      
        var nodeId = @item.link;
        var link = (@item.HasValue("link")) ? umbraco.uQuery.GetNode(nodeId).Url : "#";
    }

     

    @link is correctly filled according to item.link

    This code si the same but is not working:

    @foreach(var slide in Model.SiteSettings.First().HomepageTopSlides.First().Children)
    {
        @if(slide.HasValue("actionButtonCaption") && slide.HasValue("actionButtonLink"))
        {
            var nodeId = @slide.actionButtonLink;
            var link = umbraco.uQuery.GetNode(nodeId).Url;
    var n = Library.NodeById(1117); } }

     

     @slide.actionButtonLink --> link to a specific node
    @link is not filled and I get this error in the log file:
    Exception: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: The best overloaded method match for 'umbraco.uQuery.GetNode(string)' has some invalid arguments

    Could anyone help me?
    What's wrong in my code? and why the same code is not working in these two different cshtml files?

    Thanks in advance.

     

    Dams

     

  • Pancheri Damien 16 posts 35 karma points
    Mar 22, 2013 @ 11:33
    Pancheri Damien
    0

    Juste found the answer through many tries/errors:

    in the second (not working) example, I just tried this:

    var nodeId = slide.actionButtonLink 
    varlink=umbraco.uQuery.GetNode(nodeId.Value).Url; 

    It works!

    I don't get it! Why two identic loops work with different codes? Can someone light my way?

    Thanks.

Please Sign in or register to post replies

Write your reply to:

Draft