Вот мой контроллер:
[HttpPost]
public FileResult Download(TrainingModel pass)
{
return File(pass.filePath, "image\jpg", "haha.jpg");
}
А вот и мой AJAX:
function fncDownloadImage(fileName)
{
//passes the fileName the parameter to the Model
var download = {'filePath' : fileName}
$.ajax({
type: "POST",
url: '/Capability/Download',
data: JSON.stringify(download),
contentType: 'application/json; charset=utf-8',
success: function (response) {
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
}
Как скачать файл с вышеуказанным кодом? Когда я проверял вкладку Network
на Developer Tools
, изображение присутствует на Preview
.