Extjs Ajax file download request C# MVC

南楼画角 提交于 2019-12-05 07:53:05
sra

To handle a Download you should use one of the provided helper

  • System.Web.MVC.FilePathResult
  • System.Web.MVC.FileStreamResult
  • System.Web.MVC.FileContentResult

Most times I am using the System.Web.MVC.FileStreamResult mayself. Use it like

FileStreamResult result = new FileStreamResult(stream, contentType);
result.FileDownloadName = filename; // name of the downloaded file

Update Just some Infos based on your edit

You cannot start download using XHR request. But there are at least two ways how you can do it:

  • If the file-path is fix and you know it set top.location.href = "YourPath"; within the success handler of the ajax call. [Infos about top.location.href]
  • If you create the file on the fly and want to return it you should create a hidden iframe and inject a form into it that then execute the request.

After some search, I found that location.href does the same thing and opens a download dialog box. Same headers should be added to the response coming from the server. However, I still don't know why the other approach does not work.

var feed_id = this.getMyfeedwindow().down('form').getComponent('FeedId').text;
location.href = '/Feed/Download?fileID=' + feed_id;

this solved my problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!