i am facing problem on file response , its not downloading file, please check following code containing controller method and Ajax post call,
the object there is to input an excel file from user on the form, read and calculate the data on conditions and make results accordingly and return the byte array in file response to browser.
everything working smooth, the input file working fine , data reading working fine, just issue there on the response, its not showing any error and pass through all code without error with file not downloading.
[HttpPost]
public async Task<ActionResult> UploadCallingDocument(UploadCallingViewModel model)
{
try
{
FormFileCollection files = Request.Form.Files as FormFileCollection;
{
IFormFile file = files[0];
if (file != null && file.Length > 0)
{
var stream = file.OpenReadStream();
var result = await importExportFileManager.KeepAndShareFileAsync(stream);
return File(result, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Summarized_KeepAndShare_File.xlsx");
}
}
}
catch (Exception ex)
{
//to create error notification
}
return RedirectToAction("UploadCalling");
}
$('form').submit(function (event) {
event.preventDefault();
var formdata = new FormData($(this).get(0));
$.ajax({
url: this.action,
type: this.method,
data: formdata,
processData: false,
contentType: false,
beforeSend: function () {
// Doing some loading gif stuff
//displayBusyIndicator();
},
success: function (data) {
console.log('success');
//hideBusyIndicator();
},
complete: function () {
console.log('complete');
//hideBusyIndicator();
}
});
return false;
});