I'm trying to do a post in jquery to a MVC controller. The problem is that I need to post data from 2 different classes:
here is the controller which should receive a single class entity and then a list of entities of another class
public ActionResult Create(
PAPER_OPERATION_PRODOTTI info,
List<PRICING_PERIOD_EXT> pp_buy
){
...
Is this possible?
$.ajax({
type: 'POST',
url: getRootURL() + "/OperazioniPaperProdotti/Create",
dataType: 'json',
data: JSON.stringify(swap_all),
contentType: "application/json; charset=utf-8",
success: function (result) {
alert('im back');
alert(data);
},
error: function (xhr, ajaxOptions, error) {
alert(xhr.status);
alert('Error: ' + xhr.responseText);
}
});
At the moment I'm passing to the controller an array where I'm putting all the data... it doesn't work
var swap_all = new Array();
......
var pricing_list = new Array();
for (var c = 0; c < num_righe_to_update; c++) {
var pricing = new Array();
var id_to_op = "#ID_PRICING_PERIOD_" + c;
var data_s_to_op = "#DATA_START_" + c;
var data_e_to_op = "#DATA_END_" + c;
var div_flag_op = "#FLAG_OP_ON_SAVE_" + c;
var div_flag_linea = "#ID_LINEA_" + c;
pricing = { 'ID_PRICING_PERIOD': $(id_to_op).val(), 'DATA_START_PREZZATURA': $(data_s_to_op).val(), 'DATA_END_PREZZATURA': $(data_e_to_op).val(), 'FLAG_OP_ON_SAVE': $(div_flag_op).val(), 'ID_LINEA': $(div_flag_linea).val() };
pricing_list.push(pricing);
}
......
var swap = new Array();
swap = {
'ID_OPERAZIONE': $("#ID_OPERAZIONE").val(),
'NUMERO_CONTRATTO': $("#NUMERO_CONTRATTO").val(),
'BOOKING_COMPANY_CODE': $("#BOOKING_COMPANY_CODE").val(),
'ID_CONTROPARTE': $("#ID_CONTROPARTE").val(),
'DATA_CONTRATTO': $("#DATA_CONTRATTO").val(),
'DATA_CHIUSURA': $("#DATA_CHIUSURA").val(),
'MARKET_CODE': $("#MARKET_CODE").val(),
'QUOTAZIONE_CODE': $("#QUOTAZIONE_CODE").val(),
'UOM_PRIMARY': $("#UOM_PRIMARY").val()
};
swap_all.push(swap);
swap_all.push(pricing_list);
How can I pass these data in the right way?
Thank you!