[CLOSED] How to send dictionary(of string, string) as clientconfig?

  1. #1

    [CLOSED] How to send dictionary(of string, string) as clientconfig?

    I created a DialogWindow class that inherits from Coolite.Window that has an associated clientside Ext.ux.DialogWindow class. In the client class, I have a params property that's just an object. How can I create a clientconfig serverside property in my DialogWindow class that will serialize correctly? I tried:

            Private _URLParams As New Dictionary(Of String, String)
            ''' <summary>
            ''' Query string parameters to send to dialog
            ''' </summary>
            <ClientConfig("urlParams", JsonMode.UnrollCollection)> _
            <DefaultValue(CType(Nothing, Object))> _
            <Category("Config Options")> _
            Public Property URLParams() As Dictionary(Of String, String)
                    Return _URLParams
                End Get
                Set(ByVal value As Dictionary(Of String, String))
                    _URLParams = value
                End Set
            End Property
    However, I don't see it as part of the rendered script. Is there anything special I need to do? In ASP.NET, dictionary(of string, string) is serialized as a javascript object.
  2. #2

    RE: [CLOSED] How to send dictionary(of string, string) as clientconfig?

    Argh...I always find the answer AFTER I make a post about it. Please let me know if this is the right way to do it. I basically created my own StringDictionaryJsonConverter:

        Public Class StringDictionaryJsonConverter
            Inherits JsonConverter
            Public Overloads Overrides Function CanConvert(ByVal valueType As Type) As Boolean
                Return GetType(Dictionary(Of String, String)).IsAssignableFrom(valueType)
            End Function
            Public Overloads Overrides Sub WriteJson(ByVal writer As JsonWriter, ByVal value As Object)
                Dim dictionary As Dictionary(Of String, String) = TryCast(value, Dictionary(Of String, String))
                If dictionary IsNot Nothing Then
                    Dim iterator As Dictionary(Of String, String).Enumerator = dictionary.GetEnumerator()
                    While iterator.MoveNext()
                    End While
                End If
            End Sub
            Public Overloads Overrides Function ReadJson(ByVal reader As Newtonsoft.Json.JsonReader, ByVal objectType As Type) As Object
                Throw New NotImplementedException()
            End Function
        End Class
  3. #3

    RE: [CLOSED] How to send dictionary(of string, string) as clientconfig?

    I originally used LoadConfig.Params as an example so is that a bug?

            Dictionary<string, string> paramItems = new Dictionary<string, string>();
            [Description("Custom list of parameters passed to the url.")]
            public virtual Dictionary<string, string> Params
                    return this.paramItems;
                    this.paramItems = value;
  4. #4

    RE: [CLOSED] How to send dictionary(of string, string) as clientconfig?


    I don't think that is a bug. With Mode Json.UnrollCollection the ClientConfig builder try to serialize each item of collection to one object. The item of Dictionary is KeyValuePair which don't have properties with ClientConfig attribute (please note that only such properties can handled by ClientConfig builder). Therefore serialization for dictionary is empty

    I think that your solution with JsonConverter is good.

    Hope this help

Similar Threads

  1. [CLOSED] How to send the variable string in AutoLoadParams
    By ViDom in forum 1.x Legacy Premium Help
    Replies: 10
    Last Post: Jul 25, 2011, 11:40 AM
  2. Can I send a string with html tag to Ajaxmethod?
    By masudcseku in forum 1.x Help
    Replies: 1
    Last Post: Jul 19, 2011, 10:31 PM
  3. Replies: 4
    Last Post: Feb 01, 2011, 11:54 AM
  4. [CLOSED] Dictionary(of long, string) into a store
    By CMA in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Dec 21, 2009, 7:21 AM
  5. Replies: 1
    Last Post: Aug 25, 2009, 10:27 AM

Posting Permissions