相关疑难解决方法(0)

如何从MVC控制器提供要下载的文件?

在WebForms中,我通常会有这样的代码让浏览器显示一个"下载文件"弹出窗口,其中包含任意文件类型,如PDF和文件名:

Response.Clear()
Response.ClearHeaders()
''# Send the file to the output stream
Response.Buffer = True

Response.AddHeader("Content-Length", pdfData.Length.ToString())
Response.AddHeader("Content-Disposition", "attachment; filename= " & Server.HtmlEncode(filename))

''# Set the output stream to the correct content type (PDF).
Response.ContentType = "application/pdf"

''# Output the file
Response.BinaryWrite(pdfData)

''# Flushing the Response to display the serialized data
''# to the client browser.
Response.Flush()
Response.End()
Run Code Online (Sandbox Code Playgroud)

如何在ASP.NET MVC中完成相同的任务?

asp.net-mvc download

108
推荐指数
3
解决办法
10万
查看次数

标签 统计

asp.net-mvc ×1

download ×1