我有一塊通過發送和數組和一個int的JavaScript。MVC JavaScript方法調用不會啓動excel保存對話框
var InvoicesAndId = { values: indexArray, Id:3 };
$.ajax({
type: "POST",
url: 'Invoice/Export',
data: postData,
success: function (data) {location.replace(window.location.pathname); },
dataType: "json",
tradional: true
});
所以這個呼籲我的控制器的方法:
public void Export(InvoicesAndId invoicesAndId)
{
...
Response.AppendHeader("content-disposition", "attachment; filename" + "invoices.csv");
Response.ContentType = "application/ms-excel";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
Response.Write("word");
Response.End();
}
所以與調試我發現,InvoicesAndId正確填充。問題是一個對話框應該出現是否打開或保存excel文件。
這沒有發生。
我知道這與我如何調用函數有關,因爲如果我用ActionLink調用它,對話框會出現。
我在做什麼錯?這與ajax調用有關嗎?
如何解決這個問題?我無法使用ActionLink,因爲不可能有方法來填充參數。
我不明白這一點。你爲什麼改變接受的答案?你的問題不是關於MVC ActionResult,而是關於JavaScript。 Darin的回答很好,我也贊成。我的回答不正確或無用嗎?我錯過了什麼嗎? –