Consider the need to return a text file from the controller method back to the caller. The idea is to download the file, rather than treat it as plain text in a browser.
I have the following method and it works as expected. The file is provided to the browser for download, and the file is populated with a line.
I would like to find a "more correct" implementation of this method, since I am not 100% comfortable with the void return type.
public void ViewHL7(int id) { string someLongTextForDownload = "ABC123"; Response.Clear(); Response.ContentType = "text/plain"; Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}.hl7", id.ToString())); Response.Write(someLongTextForDownload); Response.End(); }
asp.net-mvc download controller
p.campbell Oct. 14 '09 at 23:18 2009-10-14 23:18
source share