So I have a string that I want to pass through Ajax into a C# controller to download it as a text file. But when the controller action runs, it never initiates a file download.
$('#download').click(function () {
var jsonString = JSON.stringify(allLists);
$.ajax({
url: '/Home/Download',
data: {data: jsonString},
type: 'POST'
}).done(function (result) {
debugger;
}).fail(function (a, b, c) {
console.log(a, b, c);
});
});
Here is the C#:
public FileResult Download(string data)
{
return File(new UTF8Encoding().GetBytes(data.ToString()), "text/plain", "JsonOutput.txt");
}
there are no errors, it hits the success function but never initiates a download. I'm using Chrome. Any idea what I could do differently?