I am generating a small Json file which i wan't the user to download. So i want the browser to prompt the user to download the file.
I've tried many of answers suggested in related questions but those won't work for me.
The request is made by a click on an actionlink:
@Ajax.ActionLink("Generate JSON", "GenerateOcJson", new AjaxOptions { HttpMethod = "POST" })
i've tried:
var cd = new System.Net.Mime.ContentDisposition { FileName = fileName, Inline = false };
Response.AppendHeader("Content-Disposition", cd.ToString());
return File(Encoding.UTF8.GetBytes(jsonString),
"application/json",
string.Format(fileName));
and:
Response.Clear();
Response.ContentType = "application/json";
Response.AppendHeader("Content-Disposition", "attachment; filename=foo.json");
Response.Write(jsonString);
Response.End();
But the browser won't download the file. I'm using MVC3 and this method is called by an actionlink. I've tried POST and GET requests.
If I inspect the request with Chrome i see the correct json had been written to the browser response.
Any clues? Thnx in advance