Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending a JSON array to be received as a Dictionary<string,string>

I have a method with the following signature:

public ActionResult RenderFamilyTree(string name, Dictionary<string, string> children)

I'm trying to call it from javascript using jQuery like this:

$('#div_render').load(
    "<%= Url.Action("RenderFamilyTree") %>", 
    { 
         'name': 'Raul',
         [
             {'key':'key1','value':'value1'},
             {'key':'key2','value':'value2'}
         ] 
    }, 
    function() {                
        alert('Loaded');
    }
);

Am I missing something to get this to work?

like image 800
James Bond Avatar asked Mar 22 '10 17:03

James Bond


1 Answers

There is a syntax error in the javascript object literal. The two key/value pairs in the array should be assigned to a named property alongside "name" (ex: "myProperty").

$('#div_render').load(
"<%= Url.Action("RenderFamilyTree") %>", 
{ 
     name: 'Raul',
     myProperty: [
         {key:'key1',value:'value1'},
         {key:'key2',value:'value2'}
     ] 
}, 
function() {                
    alert('Loaded');
}

);

like image 181
kwcto Avatar answered Nov 15 '22 00:11

kwcto