I have a piece of javascript which sends through and array and an 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
});
So this calls the method on my Controller:
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();
}
So with the debugger I've found that InvoicesAndId is populated correctly. The problem is a dialog is supposed to come up saying whether to open or save the excel file.
This doesn't happen.
I know this has something to do with how I'm calling the function because if I call it with an ActionLink the dialog appears.
What am I doing wrong? Is it something to do with the ajax call?
How to fix this? I can't use an ActionLink because there wouldn't probably be a way to populate the parameters.