Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. //
  2. //JS
  3. //
  4. function testDownload()
  5. {
  6. $.ajax({
  7. cache: false,
  8. type: "POST",
  9. url: '@Url.Action("myTest", "Home")',
  10. success: function (result) {
  11. //window.location = result.location;
  12. alert(result.location);
  13. },
  14. error: function () {
  15. alert("Failed.");
  16. }
  17. });
  18. }
  19.  
  20. //
  21. //C#
  22. //
  23. [HttpPost]
  24. public ActionResult myProva()
  25. {
  26. byte[] fileBytes = System.IO.File.ReadAllBytes(@"C:\Users\MyUser\Desktop\MyFile.txt");
  27. string fileName = "MyFile.ext";
  28. Response.Headers.Add("Content-Disposition", $"attachment; filename=\"{fileName}\"");
  29. return File(fileBytes, "application/txt", fileName);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement