I have no response on the browser even though there are no error in my code and I have no idea what went wrong.
Code reach return File(memoryStream, contentType, "test" + extension);
without error but I get no response from browser.
[HttpPost]
public ActionResult DownloadAttachment(eNotice.attachment attachment)
{
try
{
var attachmentToDownload = db.Tbl_ENoticeAttachements.Where(a => a.ENID == attachment.ENID && a.IsDeleted == false && string.Compare(a.FileName, attachment.FileName, StringComparison.OrdinalIgnoreCase) == 0).FirstOrDefault();
if (System.IO.File.Exists(attachmentToDownload.FilePath + @"\" + attachmentToDownload.FileName))
{
var file = System.IO.File.ReadAllBytes(attachmentToDownload.FilePath + @"\" + attachmentToDownload.FileName);
var extension = Path.GetExtension(attachmentToDownload.FileName);
MemoryStream memoryStream = new MemoryStream(file);
byte[] bytes = memoryStream.ToArray();
memoryStream.Seek(0, SeekOrigin.Begin);
var contentType = System.Web.MimeMapping.GetMimeMapping(attachmentToDownload.FileName);
return File(memoryStream, contentType, "test" + extension);
}
else
{
return null;
}
}
catch (Exception exception)
{
exception = exception;
return null;
}
}
The code above is call via javascript:
$('#buttonTest').click(function () {
var ENID = $(this).data('enid');
var FileName = $('#buttonTest').val();
var formData = "{FileName:'" + FileName + "',ENID:'" + ENID + "'}";
makeAjaxCall("", '@Url.Action("DownloadAttachment", "eNotice")', formData, "", "", "");
});