I am submitting a form that is sending a request to the backend, C# action. The backend generates a pdf file and sends it back to the browser to download it. How do I catch this event? I simply want to display a message to the user when the pdf is sent from the server. I cannot use ajax because I am sending a request through the form and I expect the response to be an attachment.
public ActionResult ConvertHTMLtoPDF(string htmltoPDfFullUrl)
{
Byte[] res = null;
using (MemoryStream ms = new MemoryStream())
{
// not important logic
}
var stream = new MemoryStream(res);
return new FileStreamResult(stream, "application/pdf")
{
FileDownloadName = "some name.pdf"
};
}
$(document).on('click', ".formSubmitDiv", function () {
formSubmit();
})
function formSubmit() {
$('#htmltoPDfFullUrl').val(fullHTMLLIVE);
document.getElementById('beginConvertHTMLtoPDF').submit();
}
@using (Html.BeginForm("ConvertHTMLtoPDF", "Home", FormMethod.Post, new { id = "beginConvertHTMLtoPDF" }))
{
<input type="hidden" name="htmltoPDfFullUrl" id="htmltoPDfFullUrl" />
}