Copied to clipboard

Flag this post as spam?

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


  • UmbracoTests 29 posts 180 karma points
    Nov 15, 2023 @ 23:20
    UmbracoTests
    0

    Getting a value from getproperty getvalue

    How do you access these values for example Colour in this image? To get the values I did evt.Getproperty("category").GetValue(). I am also doing this in a controller so I can pass the value to the view.

    enter image description here

    I have tried many ways to no avail. Thanks

  • Marc Goodson 2149 posts 14377 karma points MVP 9x c-trib
    Nov 22, 2023 @ 17:45
    Marc Goodson
    101

    Hi UmbracoTests

    Sounds like you have an Event that can pick a Category, which is another Umbraco content item and in this Category there is a colour property?

    A lot depends on if you are using Modelsbuilder and strongly typed models or just the underlying IPublishedContent representation of Umbraco items...

    Anyway if evt is your event model you should be able to get the picked category via

    var category = evt.Value<IPublishedContent>("category");

    (unless the picker allows multiple categories then it would be... & lt;IEnumerable<IPublishedContent>>)

    When you have your category you can then access its properties via

    var colour = category.Value<string>("colour");

    If you are using Modelsbuilder then you would be able to cast your picked item into the associated content model eg

    var category = evt.Value<IPublishedContent>("category") as Category; var colour = category.Colour;

    Regards

    Marc

  • UmbracoTests 29 posts 180 karma points
    Nov 30, 2023 @ 01:07
    UmbracoTests
    0

    Thanks. This did the trick!

Please Sign in or register to post replies

Write your reply to:

Draft