Copied to clipboard

Flag this post as spam?

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


  • Harry Spyrou 212 posts 604 karma points
    Oct 07, 2016 @ 07:51
    Harry Spyrou
    0

    How to find a Property Value from within the controller with Umbraco Helper?

    So, I have been trying to make an AJAX call and I want to return the data of a bunch of children nodes that don't have a template to the call so it can display them as I told it to.

    I tried getting the nodes in a few ways but nothing seems to be working. I basically wanted to store the property value in a variable and then pass it to the call. Last one I've tried was this. I'm using Surface Controllers.

    var findInUmbraco = Umbraco.Content(1063).DescendantsOrSelf("lekseisDiatrofikouLeksikou").GetPropertyValue(query);
    

    What am I missing? I know that as a thought it's correct, but my execution sucks.

  • Alex Skrypnyk 6148 posts 24097 karma points MVP 8x admin c-trib
    Oct 09, 2016 @ 09:18
    Alex Skrypnyk
    0

    Hi Harry,

    Is this - lekseisDiatrofikouLeksikou - document type alias of child nodes?

    Do you have some exceptions?

    I would write this code in strongly typed manner:

    var findInUmbraco = Umbraco.TypedContent(1063).DescendantsOrSelf("lekseisDiatrofikouLeksikou").Select(x => x.GetPropertyValue(query));
    

    Also please remember that DescendantsOrSelf() returns list, so GetPropertyValue of list can be error.

    Hope it will help you.

    Thanks,

    Alex

  • Harry Spyrou 212 posts 604 karma points
    Oct 10, 2016 @ 13:19
    Harry Spyrou
    0

    I'm sorry, no I didn't solve it, but I don't even know if that's the problem anymore. Anyway yes lekseisDiatrofikouLeksikou is an alias of a node which is a child node, you're correct. I'm going to try your code right now and let you know.

  • Alex Skrypnyk 6148 posts 24097 karma points MVP 8x admin c-trib
    Oct 10, 2016 @ 13:15
    Alex Skrypnyk
    0

    Hi Harry,

    Did you solve your problem?

    Can you share code?

    Thanks,

    Alex

  • Harry Spyrou 212 posts 604 karma points
    Oct 10, 2016 @ 13:21
    Harry Spyrou
    0

    Looks like the code doesn't work completely but I fixed it.

    I couldn't work it with TypedContent but it did work as Content. Thanks for the help. The working code is:

    var findInUmbraco = Umbraco.Content(1063).DescendantsOrSelf("lekseisDiatrofikouLeksikou").Select(x => x.GetPropertyValue(query));
    
  • Alex Skrypnyk 6148 posts 24097 karma points MVP 8x admin c-trib
    Oct 10, 2016 @ 13:23
    Alex Skrypnyk
    0

    So topic is solved!

    Glad to help you Harry. Have a nice day.

    Thanks,

    Alex

  • Harry Spyrou 212 posts 604 karma points
    Oct 10, 2016 @ 13:30
    Harry Spyrou
    0

    Actually it's not. When I changed it to dynamic with Content the lambda expression created an error. Says I can only use it with TypedContent. However, TypedContent doesn't allow to search for Descendants.... Looking on it now.

  • Alex Skrypnyk 6148 posts 24097 karma points MVP 8x admin c-trib
    Oct 10, 2016 @ 14:02
    Alex Skrypnyk
    0

    Harry, which version of Umbraco are you using?

    This code works for me:

    var findInUmbraco = Umbraco.TypedContent(1063).DescendantsOrSelf("lekseisDiatrofikouLeksikou").Select(x => x.GetPropertyValue("yourAlias"));
    
  • Harry Spyrou 212 posts 604 karma points
    Oct 10, 2016 @ 14:05
    Harry Spyrou
    0

    Just copy pasting your code: "Cannot convert lambda expression to type 'string' because it is not a delegate type'.

  • Alex Skrypnyk 6148 posts 24097 karma points MVP 8x admin c-trib
    Oct 10, 2016 @ 14:50
    Alex Skrypnyk
    100

    Harry,

    Try this one:

    var findInUmbraco = Umbraco.TypedContent(1063).DescendantsOrSelf().Where(x => x.DocumentTypeAlias.Equals("lekseisDiatrofikouLeksikou")).Select(x => x.GetPropertyValue("yourAlia"));
    
  • Steve Morgan 1348 posts 4457 karma points c-trib
    Oct 10, 2016 @ 14:57
    Steve Morgan
    1

    Add a using System.Linq to the top.

  • Harry Spyrou 212 posts 604 karma points
    Oct 10, 2016 @ 15:01
    Harry Spyrou
    0

    You guys both rock. Thank you!

  • Alex Skrypnyk 6148 posts 24097 karma points MVP 8x admin c-trib
    Oct 10, 2016 @ 15:01
    Alex Skrypnyk
    0

    We are happy to help!

    Have a nice day.

    Alex

  • Harry Spyrou 212 posts 604 karma points
    Oct 10, 2016 @ 15:10
    Harry Spyrou
    0

    You too.

Please Sign in or register to post replies

Write your reply to:

Draft