【发布时间】:2012-02-25 04:56:22
【问题描述】:
我正在尝试将 Guid 的数组/IEnumerable 传递给 MVC 'GET' 方法,如下所示:
[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" };
}
我的 javascript 看起来像这样:
$('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(){
}
});
});
我的期望是这将在浏览器上弹出下载对话框。实际上,传递给控制器的 javascript 数组为空(在服务器端,它在客户端正常工作)。此外,这适用于“POST”,但是,以这种方式使用的“POST”方法不会强制下载对话框...
欢迎提出建议 :)
【问题讨论】:
标签: c# jquery asp.net .net asp.net-mvc-3