Copied to clipboard

Flag this post as spam?

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


  • Lex Godthelp 24 posts 106 karma points
    Jul 05, 2015 @ 20:33
    Lex Godthelp
    0

    Getting property values in var

    Hi guys,

    There's something really confusing in Razor which i can't seem to explain. Dennis helped me sort out some stuff with comparing id's from a currentPage with a foreach item. But now i want to compare a property value from one node to a property value from another node and see if they match:

    @{
    var startNodeId = 1239;
    IPublishedContent currentNode = UmbracoContext.Current.ContentCache.GetById(CurrentPage.Id);
    IPublishedContent currentNodeExpertid = @currentNode.GetPropertyValue("responseitemexpertid")
    }
    @if (startNodeId != null)
                {
                    @* Get the starting page *@
                    var startNode = Umbraco.Content(startNodeId);
                    var selection = startNode.Children.Where("expertid == @0", "1");
    }
    

    This code works because i hard coded the responseitemexperid with "1" in my var selection. But if i try to replace "1" with a property value from the current node, the script crashes on me. What am i doing wrong and why?

    var selection = startNode.Children.Where("expertid == @0, currentNodeExpertid)
    
  • Lex Godthelp 24 posts 106 karma points
    Jul 06, 2015 @ 13:11
    Lex Godthelp
    1

    Okay guys, i found the solution:

     @{
    var startNodeId = 1239;
    var currentNode = CurrentPage.Id;
    var currentNodeContent = Umbraco.Content(currentNode);
    var currentNoderesponseitemexpertid = currentNodeContent.Responseitemexpertid;
    }
    @if (startNodeId != null)
                {
                    @* Get the starting page *@
                    var startNode = Umbraco.Content(startNodeId);
                    var selection = startNode.Children.Where("expertid == @0", currentNoderesponseitemexperid);
    }
    

    This seems to work perfectly. First, i made a var where i get the currentpage id. Then i made a var which gets the content from the currentpage using the currentpage id. Then i made a third var in which i call the value of a property in the content from the currentpage. Might not be the best solution, but it works :D

    Special thanks to Dennis Aaen

Please Sign in or register to post replies

Write your reply to:

Draft