我有一个视图,我从 Jqgrid 中的一行获取信息,然后使用该信息作为参数对控制器进行 ajax 调用。参数正在传递给控制器,但是当它没有执行我想要的操作时,我正在尝试创建一个 csv 文件。
看法:
function sendParams() {
var selId = jQuery("#list").jqGrid('getGridParam','selrow');
var data = jQuery("#list").jqGrid('getRowData',selId);
$.ajax({
type: "GET",
url: '@Url.Action("ExportToExcel","Home")',
data: {sidx: 'abcd', sord: 'desc', page:1, rows: 100, id: data.selId, rid: data.id, process: data.process, detail_table: data.detail_table, jobGroup: @Html.Raw(Json.Encode(@ViewBag.jobGroup)), date: @Html.Raw(Json.Encode(@ViewBag.DateSelected))},
contentType: "application/json; charset=utf-8",
});
}
<button onclick="function sendParams()">Export</button>
控制器
public ContentResult ExportToExcel(String sidx, String sord, int page, int rows, String id, String process, String detail_table, String jobgroup, String date)
{
var sw = new StringWriter();
List<myModel alist = DAL.ExportExcelConn2.SelectGridItems(sidx, sord, page, rows, rid, process, detail_table, jobgroup, date);
foreach (var item in alist)
{
sw.WriteLine(String.Format("{0}, {1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16}", item.abc, item.sstuff, item.stuff2, item.stuff3, item.stuff4, item.stuff5, item.stuff6, item.stuff7, item.stuff8, item.stuff9, item.stuff10, item.stuff11, item.stuff12, item.stuff13, item.stuff14, item.stuff15, item.stuff16));
}
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=Exportabc" + DateTime.Now + ".csv");
Response.ContentType = "text/csv";
Response.Write(sw);
Response.End();
return Content("Test");
}