Reputation: 2374
I got JS function which use ajax
. It calls the controller which suppose to get data and parse it. It ssems like on client side data variable formed ok bu the controller gets nothing!
I call JS function like getTheDiagramm('/PPTDesign/getReceiversDiagram', recIntervalsRec.total, recIntervalsRec.records);
Here's the function as is
function getTheDiagramm(action_url, total_d, records_d) {
var mainData;
var table_form = {
total: total_d,
records: records_d
}
var postData = JSON.stringify(table_form);
$.ajax({
type: "POST",
url: action_url,
async: false,
data: postData,
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
mainData = data;
}
});
return mainData;
}
On the controller side
public JsonResult getReceiversDiagram(DesignReceiversMap postData)
{
List<string> resultData = new List<string>();
return Json(resultData, JsonRequestBehavior.AllowGet);
}
Models
public class Design {
public int recid;
public String well;
public String q1;
public String q2;
public String down;
public String up;
}
public class DesignReceivers : Design {
public String period1;
public String period2;
}
public class DesignReceiversMap {
public int total;
public List<DesignReceivers> records;
}
So, what it sends
and what controller gets
I really don't understand what's wrong. Could you help me to fix it, please?
Upvotes: 3
Views: 654
Reputation: 766
Your method public JsonResult getReceiversDiagram(DesignReceiversMap postData)
expects DesignReceiversMap object as input. But that's not what you send when you call the method.
Try this in your controller:
public JsonResult getReceiversDiagram(string postData)
and this in your js:
$.ajax({
type: "POST",
url: action_url,
async: false,
data: "postData=" + postData,
success: function (data) {
mainData = data;
}
});
then you can parse the data.
Upvotes: 1