Response.WriteFile() — not working asp net mvc 4.5

夙愿已清 提交于 2019-11-29 18:05:17

Not sure if it's your only problem, but the file name in the Content-Disposition header is supposed to be a quoted-string, so you'll need to add quotes around it, particularly since it contains spaces;

Response.AddHeader("Content-Disposition", 
    string.Format("attachment; filename=\"{0}\"", downloadName));

On a side note, Response.End() also flushes the buffer, so your Response.Flush() is redundant.

Solved the issue. I was using Ajax to call this function from one of my views. This didn't work (I am not sure why), but I think it may be because I have multiple controllers. Calling this from @HTML.ActionLink() had the prompt display properly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!