我正在使用MVC 3我想动态创建一个CSV文件供下载,但我不确定正确的MVC方向。使用响应流的MVC控制器
在传统的ASP.net,我会写这样的:
Response.ClearHeaders();
Response.ContentType = "text/csv";
Response.AddHeader("content-disposition", attachment;filename='Test.csv'");
Response.Write("1,2,3");
Response.End();
我已经看了看ContentResult类型行动,但看来我需要创建的结果作为一个字符串,即
return Content(myData,“text/csv”);
我可以,我想,建立一个字符串,但由于这些文件可能是几千行,对我来说这似乎效率低下。
难道有人指着我正确的方向吗?谢谢。
创建一个自定义的ActionResult类型,详见本文:[http://stackoverflow.com/questions/989927/recommended-way-to-create-an-actionresult-with-a-file-extension?rq=1] [1] [1]:http://stackoverflow.com/questions/989927/recommended-way-to-create-an-actionresult-with-a-file-extension?rq=1 –
看起来确实是http:///stackoverflow.com/q/943122/1178314其中有一个相当不错的答案imho(http://stackoverflow.com/a/13456219/1178314) –