I'm trying to pass an array/IEnumerable of Guids to a MVC 'GET' method that looks like this:
[HttpGet]
public ActionResult ZipResults(IEnumerable<Guid> ids)
{
using(var zip = new Zip())
{
foreach(var id in ids)
{
var stream = GetDataStream(id);
zip.AddEntry("filename.txt", stream);
}
}
var outputStream = new MemoryStream();
zip.Save(outputStream);
return FileStreamResult(outputStream, "application/octet-stream"){
FileDownloadName = "Results.zip" };
}
And my javascript looks like this:
$('the-button').click(function(){
// 1. Get the guids from a table and add to javascript array (works fine)
// 2. Grey-out screen and show processing indicator (works fine)
// 3. This is how I'm calling the "ZipResults" action:
$.ajax({
url: '@Url.Action("ZipResults", "TheController")',
type: 'GET',
data: $.toJSON({ ids: _ids }),
dataType: 'json',
contentType: 'application/json;charset=utf-8',
traditional: true,
success: function(){
// Undo the grey-out, and remove processing indicator
},
error: function(){
}
});
});
My expectation is that this will popup the download dialog on the browser. As it is, the javascript array being passed to the controller is null (on the server-side, it works correctly client-side). Also, this works fine with a 'POST', however, a 'POST' method used this way will not force the download dialog...
Open for suggestions :)