1
Answer

download file with mvc

Bahar N.V1984

Bahar N.V1984

9y
389
1
hi,
i want to write a sample to download file with ajax and mvc file result
  it is this but file not downloaded
 
 
//fileresult method 
public FileResult ExportExcel(string ID)
{
string timeMark = ID + DateTime.Now.ToString("yyyyMMdd HHmmss");
string cellByCellFilePath = Server.MapPath("~/Files/temp/") + timeMark + ".xlsx";
string fileName ="timeMark + ".xlsx";
return File(cellByCellFilePath, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);
 
}
 
//jquery function 
 
function ExportExcel() {
$.ajax({
 dataType: "json",
 url: urlcontroller,
 type: 'POST',
 contentType: 'application/json; charset=utf-8',
 data: JSON.stringify({
ID: ID
}),
success: function () {
alert("yes");
 },
error: function (xhr, ajaxOptions, thrownError) {
 }
, complete: function () {
 }
});
 
 
// css link
 
 
<a onclick="ExportExcel()"> exportexcel</a>
 
 
 
 
 
 
Answers (1)