且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用ASP.NET MVC,我可以使用jQuery GET和FilePathResult下载文件吗?

更新时间:2023-02-15 22:14:57

否.您不能使用jQuery通过下载返回文件.但是,您可以将location.href设置为传递文件的操作,它将在不更改当前页面的情况下下载文件.假定FileResult是附件,通常是附件.您应该在客户端上更改方法以使用location.href而不是jQuery get.我不确定为什么会出现访问异常.可能是,虽然您有权访问特定目录,但您的帐户却无权访问路径中的中间目录之一.

No. You cannot use jQuery to return a file via download. You can, however, set location.href to the action that delivers the file and it will download it without changing the current page. This assumes that the FileResult is an attachment, which it typically is. You should change the method on the client to use location.href instead of jQuery get. I'm not sure why you are getting the access exception. It could be that while you have access to the particular directory, your account doesn't have access to one of the intervening directories in the path.