c# - File Download Using Ajax and iframe -


i have read doing file download using ajax , iframes. can give me step step explanation of how or know of tutorials seeing using ajax on project seems best way this.

edit:

okay view code:

<div class="buttons"> <input type="button" value="download file" class="button" id="downloadfile"> 

<script type="text/javascript">     $(function () {     $('#downloadfile').click(function (e) {         $('#downloadiframe').attr('src', '@url.action("downloadfile","invoice")' + '/report/invoices');     }); }); </script> 

this controller:

public fileresult downloadfile(int id)     {          byte[] filebytes = system.io.file.readallbytes(server.mappath("~/reports/invoices/" + table.first(x => x.id == id).id + ".pdf"));         string filename = table.first(x => x.id == id).id.tostring();         return file(filebytes, system.net.mime.mediatypenames.application.pdf, filename);     }      public actionresult download(int id)     {         return ajaxresponse("download", null);     } 

i have jquery context menu use click on row in jqgrid , open view download , in view click button , should execute script in view , return downloadfile fileresult in controller nothing happens when click button.

the folder reports are: ~/reports/invoices

i don't know iframes, way of downloading files through ajax simple writing response stream.

    [httpget]     [outputcache(varybycustom="id")]     public void downloadfile(int id)     {         var path = getfilepath(id);         response.contenttype = "application/octet-stream";         response.appendheader("content-disposition", "attachment; filename=xxx");         response.writefile(path);         response.end();     } 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -