Copied to clipboard

Flag this post as spam?

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


  • James 251 posts 1169 karma points
    May 31, 2015 @ 12:29
    James
    0

    Id of current page

    Hello,

     

    I have a related content partial view that gets similar animal pages to the one the user has selected:

     

    @foreach (var page in Umbraco.Content("1061").DescendantsOrSelf("Animal"))

    {}

     

    Is there any way to tell it "Where ID is not = to current page  ID?" i dont want to see the current page in the related section choices.

     

    Thanks guys,

     

    J

     

    P.S. I am using Umbraco.Content(1061) sot hat i can stick the partial view anywhere on my site.

     

    TY

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 31, 2015 @ 12:54
    Dennis Aaen
    101

    Hi James,

    I think that you could do something like this

    @{  
        var currentPageId = CurrentPage.Id;
    
        foreach (var page in Umbraco.Content("1061").DescendantsOrSelf("Animal").Where("Visible && Id != @0",currentPageId)){ 
           // Do something 
       }
    
     }
    

    And here you can find the documentation https://our.umbraco.org/Documentation/Reference/Mvc/querying#Complexquerying%28Where%29

    Hope this helps,

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft