I need to send 500 GUIDs to MVC controller, get some data based of this Id's and return excel sheet. I have a POST method on my controller
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult ExportToExcel(List<string> contractIds)
{
var contracts = SearchContracts.ExportToExcel(string.Join(",", contractIds));
byte[] filecontent = ExcelExportHelper.ExportExcel(contracts, "Report", false, null);
return File(filecontent, ExcelExportHelper.ExcelContentTypeXlsx, "Report.xlsx");
}
If I do it way of AJAX, I need to have AJAX type: "POST"
, everything looks OK, but no file is returned to client:
function exportToExcel() {
var selectedContractsId = getSelectedContracts();
$.ajax({
type: "POST",
url: "@Url.Action("ExportToExcel", "Search")",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(selectedContractsId),
dataType: "json"
});
}
and if I do it as standard MVC action and change controller method to HttpVerbs.Get
, file is returned to client but I have a problem with URL Too Long exception and update Web.config maxUrlLength
parameter is not working for me, because 500 GUIDs is not maximum, you can choose e.g. 10000 GUIDs and it is 370 000 characters in query string.
function exportToExcel() {
var selectedContractsId = getSelectedContracts();
location.href = '@Url.Action("ExportToExcel", "Search")?contractIds=' + selectedContractsId;
}