I have an action with this code:
Response.Clear();
Response.ContentType = result.MimeType;
Response.Cache.SetCacheability(HttpCacheability.Private);
Response.Expires = -1;
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=File.pdf");
Response.BinaryWrite(result.DocumentBytes);
Response.End();
return null;
and I call this action from a View using JavaScript
$.ajax({
url: '@Url.Action("GenerateFile")',
type: "POST",
data: printData,
dataType: "json"});
My code in the action executes, but I didn't see any pdf file. I think this happens because I return null or do something else wrong. How can I fix this and show the file (show save file dialog) using JavaScript?