In controller, i create file. an开发者_如何学Cd invoke it by jquery.post. i understand that return file to view is impossible because of ajax. so i create file on disk, and return url of file to user. i think its not best way, but. my probleb now, is to know when user downloaded file, and delete it, how can i do it? or any others good ways to handle?
You don't have to use AJAX here. Just use a FileResult
for the action that sends the file to the browser and the page content will not change.
public FileResult GetFile(int id)
{
// generate file or initialize stream etc.
return File("pathtofile", "text/plain"); // replace text/plain with the actual content type
// alternative: return File(fileStream, "text/plain");
}
精彩评论