Ниже метод поможет вызывать действие из запроса Ajax из диалогового окна jQuery, и он выполняет действие и может быть закрыто диалоговое окно, как только результат возврата результата результата
Controller
[HttpGet]
public ActionResult DownloadCampaign(string filePath, string mode)
{
string contentType = string.Empty;
var sDocument = filePath;
if (!System.IO.File.Exists(sDocument))
{
return HttpNotFound();
}
if (mode == "action")
return Json(new {fileName = filePath}, JsonRequestBehavior.AllowGet);
if (sDocument.Contains(".pdf"))
{
contentType = "application/pdf";
}
else if (sDocument.Contains(".docx"))
{
contentType = "application/docx";
}
else if (sDocument.Contains(".xls"))
{
contentType = "application/xlsx";
}
return File(sDocument, contentType, sDocument);
}
JQuery - Ajax Request
$(document)
.ready(function() {
$("#btnDownload").click(function () {
var file = $("#FilePath").val();
$.ajax({
url: '@Url.Action("DownloadCampaign", "FileList")',
data: { filePath: file, mode:'action' },
method: 'GET',
dataType: 'json',
//contentType: 'application/json; charset=utf-8',
success: function(data) {
@*window.location = '@Url.RouteUrl("DownloadCampaign", "FileList", new { filePath = data1.fileName })';*@
window.location.href = "@Url.RouteUrl(new
{ Controller = "FileList", Action = "DownloadCampaign" })/?filePath=" + data.fileName + "&mode=download";
$("#downloadFile_dialog").dialog("close");
},
error: function (req, status, errorObj) {
alert("Error");
}
});
});
});
Пожалуйста, обратитесь ко мне, если вам нужна дополнительная информация об этом.
urlCompression указывает , что сжимать, а httpCompression указывает , как выполнять сжатие. Если вы работаете на IIS7.5, вам ничего не нужно указывать, динамическое и статическое сжатие включены по умолчанию, оба используют gzip; Вот некоторые ссылки на urlCompression и httpCompression .