I have dictionary which is nested as shown below:
I want to convert this object to JSON which will be used to send to controller. I have tried to convert the same to array but nothing worked for me.
array = Object.keys(dicCoachList).map(function (k) {
return dicCoachList[k];
});
Which I send to controller using ajax.
$.ajax({
url: '/Dispatch/SavePatientCoaching/',
data: { careProfessional : array },
type: "POST",
success: function (data) {
},
In controller like this.
[HttpPost]
public ActionResult SavePatientCoaching(string[] careProfessional)
{
}
If I convert my object to json it just return "{"1":[],"2":[]}" So I used array. Please help me send this data to controller.

JSON.stringify?var careProfessional = JSON.stringify(dicCoachList);which returns"{"1":[],"2":[]}"['foo', 'bar']) yet you're sending a dictionary of key/value pairs. One of them needs to be changed to the correct format. Also note that once you've fixed that you don't need to wrap the values in an object when sending from$.ajax; justdata: arraywill work.