Javascript 如果无法返回操作结果,如何返回到上一个location.href
在js端,我调用该方法:Javascript 如果无法返回操作结果,如何返回到上一个location.href,javascript,c#,Javascript,C#,在js端,我调用该方法: location.href = "Element/Download/" + elementId + "?typeFile=.pdf"; 在c侧: [路由(“元素/下载/{id}”)] 公共异步任务下载(int-id,string-typeFile=“.pdf”) { ... 如果(文件存在) 返回System.Web.Mvc.File(streams.First(),“application/octet stream”,Path
location.href = "Element/Download/" + elementId + "?typeFile=.pdf";
在c侧:
[路由(“元素/下载/{id}”)]
公共异步任务下载(int-id,string-typeFile=“.pdf”)
{
...
如果(文件存在)
返回System.Web.Mvc.File(streams.First(),“application/octet stream”,Path.GetFileName(element.Path))
其他的
?
}
如果返回FileStreamResult,一切正常,并且它不会转到location.href
但我有问题,当我找不到文件下载。如果我返回new EmptyResult()
或null
它将转到location.href
我正在尝试将new Stream()放入方法文件。但它不下载现有的文件
我是否能够返回一些内容,使其不会转到location.href或在js端编程?在js端,我将补充一点,在到达前面的一段代码之后,无论该方法的结果如何,它都不会再进一步
[Route("Element/Download/{id}")]
public async Task<ActionResult> Download(int id, string typeFile = ".pdf")
{
...
if(fileExist)
return System.Web.Mvc.File(streams.First(), "application/octet-stream", Path.GetFileName(element.Path))
else
?
}