I have a controller with parameters of different types (model, array, string and int) Something like this.
public JsonResult UpdateDemandeur(Demandeurs ddeur, Photos vImg, Array vRev, Array vLangAut, int vLangMater)
I want to POST my data thru AJAX call and I used something of this kind:
var json = JSON.stringify({
'ddeur': {
ID_Ville: xIDVille,
ID_Province: xIDProv,
CodePostal_Demandeur: xCPDdeur,
Tel1_Demandeur: xTel1Ddeur,
Tel2_Demandeur: xTel2Ddeur,
Tel3_Demandeur: xTel3Ddeur,
Courriel1_Demandeur: xCour1Ddeur,
Courriel2_Demandeur: xCour2Ddeur,
Courriel3_Demandeur: xCour3Ddeur,
Code_Conseiller: xCodeCons,
ID_SituationMatrimoniale: xIDSitMat,
ID_Sexe: xIDSexe,
Date_Naissance_Demandeur: xDteNais,
ID_TranchesRevenu: xRevDdeur,
ID_Occupation: xIDOcc,
ID_Scolarite: xIDScol,
ID_StatutLegal: xIDStatLegal,
ID_Communaute: xIDComm,
ID_SourceInformation: xIDSceInfo,
Handicape: xHandicape,
Reference: xRef,
Remarques_Demandeur: xRemDdeur,
Date_Cloture_Dossier: xDtClotureDos,
Actif_Inactif: xInActif,
Dte_Saisie: xDteSaisie,
UserId: xUsrID
},
'vImg': {
Nom_Table: 'Demandeurs',
Photo: resp
}
...
});
$.ajax({
type: "POST",
url: "../Conseiller/UpdateDemandeur",
data: json,
dataType: "json",
...
As you can see on the screenshot, my variables at the controller side come empty with no error... I have tried several things but it's been a headache since.
contentType: 'contentType: application/json,'option (and not related, but useurl: '@Url.Action("UpdateDemandeur", "Conseiller")',- always useUrl.Action()to generate the correct url)