Copied to clipboard

Flag this post as spam?

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


  • Jim 26 posts 86 karma points
    Sep 03, 2015 @ 07:31
    Jim
    0

    uDynamic checkbox values

    Hi

    I'm trying to retrieve the selected values in a uDynamic checkbox displaying countries. I'm currently using the following code to do this

    @node.GetPropertyValue("countries")
    

    This returns a comma delimited list of the keys associated with my selections

    [ "ger", "usa" ]

    rather than the text values

    Germany, USA

    How do I go about retrieving the selected text values?

    Thanks

    Jim

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Sep 03, 2015 @ 10:35
    Alex Skrypnyk
    0

    Hi Jim,

    You can use jsonSerializer.

    var dict = new JavaScriptSerializer().Deserialize<Dictionary<string,object>>(node.GetPropertyValue("countries"));
    
    //Array is also possible
    string[] result = dict.Select(kv => kv.Value.ToString()).ToArray();
    
  • Jim 26 posts 86 karma points
    Sep 03, 2015 @ 17:13
    Jim
    0

    Hi Alex

    Thanks for your reply.

    I tried adding your code to a test page and got the following compiler error

    The type or namespace name 'JavaScriptSerializer' could not be found (are you missing a using directive or an assembly reference?)
    

    I fixed this by fully qualifying the reference as follows

    var dict = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<Dictionary<string,object>>(node.GetPropertyValue("countries"));
    

    This then gave the compiler error

    The best overloaded method match for 'System.Web.Script.Serialization.JavaScriptSerializer.Deserialize<System.Collections.Generic.Dictionary<string,object>>(string)' has some invalid arguments
    

    Do you have any idea how I might resolve this?

    Thanks

    Jim

Please Sign in or register to post replies

Write your reply to:

Draft