开发者

ASP MVC 2 Files

开发者 https://www.devze.com 2023-01-14 21:22 出处:网络
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.

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");
}
0

精彩评论

暂无评论...
验证码 换一张
取 消