Copied to clipboard

Flag this post as spam?

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


  • Magnus Mårtensson 3 posts 33 karma points
    Aug 26, 2015 @ 13:39
    Magnus Mårtensson
    0

    How do I get the selected prevalue from my custom datatype radio button list?

    I have created a nice DocumentType with a nice generic property of a custom DataType. My DataType has the Property Editor set to Radio Button List and I have added five prevalues. Everything seems to be completely in order so far.

    When I navigate to a content page of this document type I can indeed see that there is such a property of the right type.

    When I try to get the value form this property I can't figure out how to get the right data? I would have expected to get the value I entered in the prevalue field and then selected in my content page. Instead I get the number '6'. I note that this number correlates exactly to [Umbraco].[db_owner].[cmsDataTypePreValues].[id] which is a bit odd? Why on earth would I get that value sent back to me?

    Neither of these work. My scenario is more that I am in code and would prefer something like the latter option below.

    var test1 = CurrentPage.localereplacement;
    var test2 = Model.Content.Properties.First(p => p.PropertyTypeAlias == "localereplacement").GetValue<string>();
    

    As stated both of these give back the number '6' and not my prevalue string.

  • Jerode 44 posts 159 karma points
    Aug 27, 2015 @ 14:23
    Jerode
    101

    Something like the following should work for you.

    string test3;
    int propertyId = node.GetProperty<int>("localereplacement");
    if (propertyId > 0)
    {
        test3 = library.GetPreValueAsString(propertyId);
    }
    
  • Magnus Mårtensson 3 posts 33 karma points
    Aug 28, 2015 @ 11:51
    Magnus Mårtensson
    0

    That's correct! Thank you that works. But it seems overly complicated to me.

Please Sign in or register to post replies

Write your reply to:

Draft