解决方法
您可以使用操作中的viewmodel或ViewData返回文件的地址,并使用window.location.href,如视图末尾的以下代码所示.
调节器
public ActionResult Index() { /* ... */ ViewBag.FileName = "{FileName}"; return View(); } public ActionResult Download(string id) { /* ... */ return File("{Path}","{MIME type}","{Desired file name}"); }
<script type="text/javascript"> window.location.href = "/home/download/" + "@Ajax.JavaScriptStringEncode(@ViewBag.FileName)"; </script>