Skip to content

Instantly share code, notes, and snippets.

@venblee
Created June 27, 2013 14:13
Show Gist options
  • Save venblee/5876745 to your computer and use it in GitHub Desktop.
Save venblee/5876745 to your computer and use it in GitHub Desktop.
Returning a File from MVC Controller. Makes user you use <a> </a>
public ActionResult Download()
{
// Get the file content as string
string fileContent = GetCSVFileContent();
// Get the bytes for the dynamic string content
var byteArray = Encoding.ASCII.GetBytes(fileContent);
string fileName = "Download File in ASP.NET MVC with dynamic content.csv";
return File(byteArray, "text/csv", fileName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment