Copied to clipboard

Flag this post as spam?

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


  • Craig O'Mahony 364 posts 918 karma points
    Oct 07, 2019 @ 13:24
    Craig O'Mahony
    0

    Unable to access node properties

    Hi all,

    I have a node which I'm trying to access the media picker property off, so I'm using the below:

    var currentPageId =  UmbracoContext.Current.PageId;
    var page = Umbraco.TypedContent(currentPageId);
    var videoPage = page.GetPropertyValue("video");
    

    So I'm getting the current page ID and converting that to TypedContent and then getting the property value (video) and loading that into videoPage.

    I can see that the variable has all of the properties I would expect but I can't 'get' them.

    enter image description here

    i.e. I would have thought that I could use @videoPage.Id but the Id value isn't exposed (none of the properties are).

    Any ideas anyone?

  • Steve Megson 151 posts 1022 karma points MVP c-trib
    Oct 07, 2019 @ 18:47
    Steve Megson
    0

    Try this:

    var videoPage = page.GetPropertyValue<IPublishedContent>("video");
    

    When you call page.GetPropertyValue(alias), the value is returned as an object. Since the compiler doesn't know what sort of value will actually be returned, you can't do much more than convert the value to a string.

    Calling GetPropertyValue<T>(alias) instead returns a T, so the compiler knows what you're expecting and can let you access its properties and methods.

Please Sign in or register to post replies

Write your reply to:

Draft