I have tried several way to download. searched several solution in SO, CP or google. I am not seeing any error or compiler is running it fine. browser is acting good. Just download is not working. Here is the downlaod code part.
.cs file
[HttpGet]
public ActionResult Download()
{
string[] s = new string[2];
using (StreamReader sr = new StreamReader(Server.MapPath("~\\test.txt")))
{
int i = 0;
while (sr.Peek()>=0)
{
s[i] = sr.ReadLine();
i++;
}
}
return File(s[0], "application/zip", s[1]);
}
.cshtml
<input type="button" id="btnDownload" value="Download" />
javascript code
$("#btnDownload").click(function () {
$.ajax({
url: '@Url.Action("Download", "Image")',
type: 'GET',
async: false,
cache: false,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (data) {
alert(1);
window.location = '@Url.Action("Download", "Image")';
}
});
});
it does not come to success alert in ajax request. goes to Download method. text file is ok. and filename and path is correct as well.
But I think, anything is wrong in the line
return File(s[0], "application/zip", s[1]);