Hi There, can some please help me how to pass serialize form data , file uploads paths and rest of the parameter like
var OfficeHolder_id="123", var AccountDetail_Id="789", var contact_person_id="8910" to the controller method below using ajax post method.
some of the sample code is below
view code
@using (Html.BeginForm("SaveApplication", "CreateApplicationFromSearch", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" id="specific_Item" name="specific_Item" multiple="multiple"/>
<input type="file" id="Position_Description" name="Position_Description" multiple="multiple"/>
<input type="file" id="Employment_Contract" name="Employment_Contract" multiple="multiple"/>
controller method
[HttpPost]
public ActionResult SaveApplication(tr_applications Application,
IEnumerable<httppostedfilebase> specific_Item, IEnumerable<httppostedfilebase> Position_Description,
IEnumerable<httppostedfilebase> Employment_Contract,string OfficeHolder_id, int? AccountDetail_Id, string contact_person_id)
What I have tried:
$('#btnSaveClose').click(function () {
var fileUpload = $("#Resolution_ToApply").get(0).files;
var files = fileUpload.files;
var fileData= new FormData();
// Looping over all files and add it to FormData object
for (var i = 0; i < files.length; i++) {
fileData.append(files[i].name, files[i]);
}
$.ajax({
url: "/CreateApplicationFromSearch/SaveAndCloseApplication",
type: "POST",
contentType: false, // Not to set any content header
processData: false, // Not to process data
data: fileData,
success: function (response) {
if (response != null && response.success) {
} else {
alert(response.responseText);
}
},
error: function (response) {
alert("error!" + response.responseText);}
});
});