Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- //JS
- //
- function testDownload()
- {
- $.ajax({
- cache: false,
- type: "POST",
- url: '@Url.Action("myTest", "Home")',
- success: function (result) {
- //window.location = result.location;
- alert(result.location);
- },
- error: function () {
- alert("Failed.");
- }
- });
- }
- //
- //C#
- //
- [HttpPost]
- public ActionResult myProva()
- {
- byte[] fileBytes = System.IO.File.ReadAllBytes(@"C:\Users\MyUser\Desktop\MyFile.txt");
- string fileName = "MyFile.ext";
- Response.Headers.Add("Content-Disposition", $"attachment; filename=\"{fileName}\"");
- return File(fileBytes, "application/txt", fileName);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement