English 中文(简体)
MVC 返回 CSV文件的 MVC 行动
原标题:MVC Action returning a CSV File

我有一个行动 负责从数据库取出一些数据 并把它归还为CSV文件

我知道我可以用一个巨大的绳子 返回一个巨大的弦来做到这一点, 但我在想,如果有一个干净和高效的方法, 可以用一个MVC控制器的动作 来返回一个 CSV文件。

问题回答

您正在寻找的文件Result :

http://msdn.microsoft.com/en-us/library/system.web.mvc.fileresources.aspx" rel=“norefererr'>http://msdn.microsoft.com/en-us/library/system.web.mvc.fileresult.aspx

public ActionResult GetFile()
{
    var stream = new StreamReader("thefilepath.txt");
    return File(stream.ReadToEnd(), "text/plain");
}

最佳方面





相关问题
Styling rows in table that uses CSV data through PHP

I ve been working on this simple code that puts a CSV file into a nice table. But because the data is imported, styling ODD rows is a pretty hard thing to do. All I need would be a method to address ...

PHP - Sanitise a comma separated string

What would be the most efficient way to clean a user input that is a comma separated string made entirely on numbers - e.g 2,40,23,11,55 I use this function on a lot of my inputs function clean($...

marking duplicates in a csv file

I m stumped with a problem illustrated in the sample below: "ID","NAME","PHONE","REF","DISCARD" 1,"JOHN",12345,, 2,"PETER",6232,, 3,"JON",12345,, 4,"PETERSON",6232,, 5,"ALEX",7854,, 6,"JON",12345,, ...

Interactive heat map in Flex

I’m at a very basic level with Flex and with programming in general. I am working on a project where I have data in an Excel (.csv) format, it’s a large Excel plot/matrix where each cell has a ...

热门标签