I am able to request a file and also have it returned. I don´t know how to display a open/save dialog box.
View:
function saveDocument() {
$.ajax({
url: '/Operacao/saveDocument',
type: 'POST',
DataType: "html",
success: function (data) {
//I get the file content here
}
});
}
Controller:
public void saveDocument() {
Response.ContentType = "image/jpeg";
Response.AppendHeader("Content-Disposition", "attachment; filename=SailBig.jpg");
Response.TransmitFile(Server.MapPath("~/MyPDFs/Pdf1.pdf"));
Response.End();
}
I think you cannot download a file in a browser async, just redirect the user to the action and the browser will open a save dialog window. In asp.net mvc you could have an action method to download a file resulting in a FileResult
with the File
method of the base controller.
public ActionResult SaveDocument()
{
string filePath = Server.MapPath("~/MyPDFs/Pdf1.pdf");
string contentType = "application/pdf";
//Parameters to file are
//1. The File Path on the File Server
//2. The content type MIME type
//3. The parameter for the file save by the browser
return File(filePath, contentType, "Report.pdf");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With