代码:
@model System.Data.DataTable
<button type="submit" class="btn btn-primary" data-dismiss="modal" aria-hidden="true"> Download</button>
[HttpPost]
public void getCSV(DataTable dt)
{
MemoryStream stream = Export.GetCSV(dt);
var filename = "ExampleCSV.csv";
var contenttype = "text/csv";
Response.Clear();
Response.ContentType = contenttype;
Response.AddHeader("content-disposition", "attachment;filename=" + filename);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(stream.ToArray());
Response.End();
}
我想允许用户在单击按钮时导出 CSV 文件。数据表应传递给方法 getCSV。请有人可以帮助我。谢谢
我不介意使用 Tempdata 来存储数据表,然后在控制器中访问它