User1168443798 posted
Hi BerrySmith,
>> The issue is with svc method - I am not able to get it in dictionary (selectedId) it is showing as NULL when I debug it.
Could you run your service? I found you define Interface with “Dictionary<int, string> selectedId”, but you implement it by “Dictionary<string, string> selectedId”. It will throw error.
I make a test to achieve your requirement to pass Dictionary from JS to WCF Rest Service.
1. Create a WCF Service
public Dictionary<int, string> GetStudentParameter(Dictionary<int, string> selectedId)
{
Dictionary<int, string> d = new Dictionary<int, string>();
d.Add(1,"D1");
d.Add(2, "D2");
return d;
}
2. Call Service from JS
function SendDictionary() {
console.log("Hello");
var selectedId = [];
selectedId.push({ Key: 1, Value: "S1" });
selectedId.push({ Key: 2, Value: "S2" });
$.ajax({
url: '/Service1.svc/GetStudentParameter',
data:'{"selectedId":'+ JSON.stringify(selectedId) +'}',
contentType: 'application/json',
type: 'POST',
dataType: 'json',
success: function (result) {
console.log(result)
}
});
}
Best Regards,
Edward