MVC Controller Using Response Stream

前端 未结 4 567
轮回少年
轮回少年 2020-12-09 12:06

I\'m using MVC 3 I would like to dynamically create a CSV file for download, but I am unsure as to the correct MVC orientated approach.

In conventional ASP.net, I wo

4条回答
  •  轮回少年
    2020-12-09 12:39

    I have found one possible solution to this problem. You can simply define the action method to return an EmptyResult() and write directly to the response stream. For example:

    public ActionResult RobotsText() {
        Response.ContentType = "text/plain";
        Response.Write("User-agent: *\r\nAllow: /");
        return new EmptyResult();
    }
    

    This seems to work without any problems. Not sure how 'MVC' it is...

提交回复
热议问题