Recommended way to create an ActionResult with a file extension

前端 未结 4 1481
余生分开走
余生分开走 2020-12-24 02:58

I need to create an ActionResult in an ASP.NET MVC application which has a .csv filetype.

I will provide a \'do not call\' email list to my marketing partners and i

4条回答
  •  被撕碎了的回忆
    2020-12-24 03:38

    I used the FileContentResult action to also do something similar.

    public FileContentResult DoNotEmailList(string username, string password)
    {
            string csv = Emails.Aggregate((a,b)=>a+Environment.NewLine + b);
            byte[] csvBytes = ASCIIEncoding.ASCII.GetBytes( csv );
            return File(csvBytes, "text/csv", "DoNotEmailList.csv");
    }
    

    It will add the content-disposition header for you.

提交回复
热议问题