【发布时间】:2011-12-05 08:36:59
【问题描述】:
我有一段 javascript,它通过数组和一个 int 发送。
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。达林的回答很好,我也投了赞成票。我的回答是错误的还是没用的?我错过了什么吗?
标签: javascript jquery asp.net-mvc