HTML Button的jQuery函数遇到了MVC FileResult的问题

我打算让这个函数调用我的MVC动作方法来返回一个CSV报告。

$(function() { $('#exportButton').click(function() { $.get('/curReport/GetCSVReport'); }); }); 

如果我按下面的代码创建一个按钮,那么当它被点击时,我会看到“打开/保存文件”窗口。

  

但是,当我更改我的按钮以使用我的jQuery函数时,虽然GetCSVReport() ,但我没有给出“打开/保存文件”窗口。

这是我的GetCSVReport()

 public FileResult GetCSVReport() { ... return fileResult; } 

如何使我的jQuery函数像onClick一样工作?

谢谢,

亚伦

使用您之前使用的相同代码:

 $(function() { $('#exportButton').click(function() { location.href = 'CurReport/GetCSVReport'; }); }); 

get触发一个Ajax调用,这是你不想要的。 您使用jQuery绑定事件,但操作保持不变。

要添加查询字符串参数,请使用:

 location.href = 'CurReport/GetCSVReport?filter=' + escape(val);