[Web开发中的零知识]
场景:
系统用户需要上传文件(批量上传有多个条目)。然后,系统会验证文件是否存在错误,如果有错误,则会生成并下载
一个日志文件已起作用:
直到下载部分已经 正常工作,这是我使用的代码:
preferenceCode
问题:
当我致电public void DownloadFile(ExcelPackage package, string fileName)
{
this.Response.Clear();
this.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
this.Response.AddHeader("content-disposition", $"attachment;filename={fileName}");
this.Response.BinaryWrite(package.GetAsByteArray());
this.Response.Flush();
this.Response.End();
}
(其中已定义此参数)时,我看到显示的消息。但是,无论我在文件{{1}之前还是之后调用this.ModelState.AddModelError(BulkUploadModelStateError, errorMessage);
,下载文件时都不会显示消息 。
---使用此代码进行下载,不会同时下载和消息---
当我下载文本文件时,我还有另一部分,只需修改AddModelError()
的内容类型和标题部分,便与此相同。
问题:
下载文件时如何显示消息?
或者,下载方法是否不正确,这就是为什么不会出现消息?如果是,那么正确的方法是什么?
其他信息:
当我尝试将DownloadFile()
替换为Response
时也会发生这种情况。