My Download Method in Controller is
public FileResult GenerateJSON()
{
string filename = "aa.json";
string filepath = VariableDeclarations.wwwPath + @"\Downloads\" + filename;
string filedata = System.IO.File.ReadAllText(filepath);
string contentType = GetContentType(filepath);
var cd = new System.Net.Mime.ContentDisposition
{
FileName = filename,
Inline = true
};
HttpContext.Response.Headers.Add("Content-Disposition",$"attachment;filename=aa.json");
return File(filedata, "application/json", filename);
}
and View Code is On button Click
function OnClickbtn() {
$.ajax({
type: "POST",
url: vGenerateUrl,
data: { },
success: function(s) {
DevExpress.ui.notify({ message: "xyz Generated", width: 1300 }, vSuccessMsgType, 3000);
},
error: function(result) {
onAjaxError(result);
}
});
}
On Button click from my view a .json file is generated and i need to download that .json file should be downloaded in browser but after multiple efforts for changing it from actionresult, contentresult and fileresult I am still not able to download a file in my browser.
what changes do I need to make in the above code to download .json file in browser?