var DownLoadFile = function (options) {
var config = $.extend(true, { method: 'post' }, options);
var $iframe = $('<iframe id="down-file-iframe" />');
var $form = $('<form target="down-file-iframe" method="' + config.method + '" />');
$form.attr('action', config.url);
for (var key in config.data) {
var $input = $('<input type="hidden" name="' + key + '"/>');
$input.val(config.data[key]);
$form.append($input);
}
$iframe.append($form);
$(document.body).append($iframe);
$form[0].submit();
$iframe.remove();
}
//檔案下載下傳按鈕調用
function exports() {
var items = $('#dgMain').datagrid('getChecked');
var NO_Item = [];
$.each(items, function (i, t) {
NO_Item.push({ cDocNO: t.cDocNO, iItem: t.iItem })
})
DownLoadFile({
url: '@Url.Action("DownLoad2", "_Excel")', //請求的url
data: { NO_Item: JSON.stringify(NO_Item) }//要發送的資料
})
}
注:Get請求Url長度有限制,當超出長度範圍可用此方法代替Get請求
轉載于:https://www.cnblogs.com/xiawg/p/10156261.html