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

前端 未结 2 726
孤城傲影
孤城傲影 2020-12-22 05:49

I\'ve looked at many resources and the following should work, however my save as dialog box is never showing (not browser specific):

Response.ContentType = \         


        
相关标签:
2条回答
  • 2020-12-22 06:42

    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.

    0 讨论(0)
  • 2020-12-22 06:45

    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.

    0 讨论(0)
提交回复
热议问题