Reputation: 11
In my code an Excel file is uploaded by user in view HTML and get the file by ajax and pass to an action method in ASP.NET MVC. My code is working fine but my problem is I want to add two more parameters pass to action method with the file. How do I achieve this?
function uploadUserProfileDetails() {
var excelUpload = $('#excelUpload').get(0);
var excelfiles = excelUpload.files;
var excelFileData = new FormData();
for (var i = 0; i < excelfiles.length; i++) {
excelFileData.append(excelfiles[i].name, excelfiles[i]);
}
$.ajax({
type: "POST",
enctype: "multipart/form-data",
url: "/VCModule/UploadVCSchedule",
data: excelFileData,
dataType: "json",
processData: false,
contentType: false,
async: false,
success: function (data) {
},
error: function (response) {
}
});
}
}
Upvotes: 1
Views: 318
Reputation: 11
Hers is the Solution working.
var awardfamilyid = 105;
//in Ajax method :-
excelFileData.append(awardfamilyid, JSON.stringify(awardfamilyid));
//In Action Method :-
int AwardFamilyID = Convert.ToInt32(Request.Form.Keys[0]);
Upvotes: 0
Reputation: 482
Try this,
var abc = {
'modelfieldname':excelFileData,
'modelfieldname1':data1,
'modelfieldname2':data2,
};
$.ajax({
type: "POST",
enctype: "multipart/form-data",
url: "/VCModule/UploadVCSchedule",
data: abc,
dataType: "json",
processData: false,
contentType: false,
async: false,
success: function (data) {
},
error: function (response) {
}
});
}
Upvotes: 1