Copied to clipboard

Flag this post as spam?

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


  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Aug 31, 2016 @ 07:57
    Jeroen Breuer
    0

    Get raw value instead of the converted value

    Hello,

    I'm using the Umbraco Core Property Value Converters. So for MNTP I always get the IEnumerable with IPublishedContent. I would like to only get the ids. I can't do the following: this.GetPropertyValue<IEnumerable<IPublishedContent>>("elements").Select(x => x.Id)

    Because this will go through the converter which means they've already been converted to IPublishedContent and I don't want that because it's bad for performance.

    Can I get the raw value for a specific property while not going through the converter?

    Jeroen

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Aug 31, 2016 @ 08:21
    Dan Diplo
    101

    Yep, you can do:

    this.GetProperty("elements").DataValue
    

    This will return the raw value. In the case of an MNTP it depends on the format of how you saved it, but usually this would be CSV so you can cast to string and then do a String.Split, something like:

    this.GetProperty("elements").DataValue.ToString().Split(',').Select(n => Convert.ToInt32(n));
    
  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Aug 31, 2016 @ 10:32
    Jeroen Breuer
    0

    Thanks. It works perfect!

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 31, 2016 @ 08:41
    Jeavon Leopold
    0

    Yes exactly what Dan says.

Please Sign in or register to post replies

Write your reply to:

Draft