Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
144
rated 0 times [  145] [ 1]  / answers: 1 / hits: 19447  / 13 Years ago, mon, august 8, 2011, 12:00:00

I am feeling dejavu, but I cannot find the answer to this:
I have an array of objects that needs to look like this when inspecting a jQ $.post call:



limiter[0].Key
limiter[0].Value


so that it is mapped in the action



public ActionResult SomeAction(Dictionary<Guid, string> dictionary) { }


However, this javascript:



// Some Guid and Some Value
var param = [ { 'Key' : '00000000-0000-00000-000000', 'Value': 'someValue' } ];

$.post('/SomeController/SomeAction/',
{
dictionary: limiter,
otherPostData: data
},
function(data) {
callback(data);
}
)


produces this when inspecting it in firebug:



limiter[0][Key] = someKey // Guid Value
limiter[0][Value] = someValue


This is in jq 1.4.2. I seem to remember some flag you need to set to render json a different way in jQ. Does this ring any bells?


More From » jquery

 Answers
58

Try like this:



var param = {
'[0].Key': '28fff84a-76ad-4bf6-bc6d-aea4a30869b1',
'[0].Value': 'someValue 1',

'[1].Key': 'd29fdac3-5879-439d-80a8-10fe4bb97b18',
'[1].Value': 'someValue 2',

'otherPostData': 'some other data'
};

$.ajax({
url: '/Home/SomeAction/',
type: 'POST',
data: param,
success: function (data) {
alert(data);
}
});


should map to the following controller action:



public ActionResult SomeAction(Dictionary<Guid, string> dictionary, string otherPostData) 
{
...
}

[#90741] Sunday, August 7, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mckaylab

Total Points: 311
Total Questions: 120
Total Answers: 93

Location: Montenegro
Member since Thu, Jun 16, 2022
2 Years ago
;