Copied to clipboard

Flag this post as spam?

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


  • Dan Sørensen 102 posts 327 karma points
    Jan 27, 2014 @ 10:32
    Dan Sørensen
    0

    get node by id in partial view

    Hello umbraco users maybe this is a simple question but now I have used to long on this. 
    on my document type I got a contentpicker which takes a content id, in my partial view I have to get the node and then use the nodes content to show on the site. 

    I tried a lot of diffendes stuff but what I was thinking would work was this. but this give me a partial view error

    var node = Umbraco.Content(CurrentPage.contentPickerValue);

     

    @node.bodyText



    and yes I get the id with CurrentPage.contentPickerValue

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jan 27, 2014 @ 10:40
    Dennis Aaen
    102

    Hi Dan,

    I think somethink like this should work:

    var id = CurrentPage.NodeById(1050);

    and if it dosen´t work with the CurrentPage you could try:

    var id = Umbraco.Content(1050);  

    You can find the documentation for the content picker here: http://our.umbraco.org/documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors/Content-Picker

    Hope this helps,

    /Dennis

  • Dan Sørensen 102 posts 327 karma points
    Jan 27, 2014 @ 11:10
    Dan Sørensen
    0

    hi Dennis
    after you also said Umbraco.Content like I already did i deleted the partial view and tried from scratch
    and now it works, really don't know what went wrong ? 

    Now im trying to make this

    if(node.NodeTypeAlias == "documentType")</p>
    {
    do somthing
    }
    


    But the NodeTypeAlias is empty ? 

    thanks for the help dennis I appreciate it

  • Dan Sørensen 102 posts 327 karma points
    Jan 27, 2014 @ 11:18
    Dan Sørensen
    0

    I found this http://our.umbraco.org/forum/developers/razor/38239-Umbraco-6-CurrentPageNodeTypeAlias-empty and tried DocumentTypeAlias and that worked for the alias but thanks for the help anyway Dennis :D

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jan 27, 2014 @ 11:20
    Dennis Aaen
    0

    Hi Dan,

    Try this one instead:

    if (CurrentPage.DocumentTypeAlias == "documentType") { 
    do somthing
    }

    Hope this work for you.

    Edit: Okay Dan you found the same as me :)

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft