I want to read json data and formdata(attachments) in my C# method from the ajax call. Need to upload the files and some json data. Unable to get the values from the ajax in my C# method.
JS Code :
function FileUploadd() {
var lang = $("ul.nav-tabs li.active a")[counterF - 1].text;
$("ul.nav-tabs li.active a").each(function() {
if (this.hash == paneId)
lang = this.innerText;
});
var jsonObjects = JSON.stringify({
'QuestionNumber': 1,
'Language': "amit",
'Countries': "C1",
'Attachments': attchmt
});
// Checking whether FormData is available in browser
if (window.FormData !== undefined) {
var fileUpload = $("#FileUpload" + qnNo).get(0);
debugger;
var files = fileUpload.files;
// Create FormData object
var fileData = new FormData();
// Looping over all files and add it to FormData object
for (var i = 0; i < files.length; i++) {
var newFile = 'Q' + qnNo + '_' + lang;
//fileData.append(files[i].name, files[i]);
files[i].Filename = newFile;
fileData.append(newFile, files[i]);
}
$.ajax({
url: '/RequirementManagement/FilesUpload',
type: "POST",
contentType: false, // Not to set any content header
processData: false, // Not to process data
data: {
fObj: jsonObjects,
fd: fileData
},
success: function(result) {
},
error: function(err) {
alert(err.statusText);
}
});
} else {
alert("FormData is not supported.");
}
};
C# Code:
public void UploadTestForm(JsonModel fObj, FormData fd)
{
//Code here
}
JsonModel is my model class and not sure what will the datatype to receive formdata. Don't know how start and proceed.