我想将 HTML 表导出到 MVC 中的 excel 中。我的控制器中有以下代码:
public JsonResult ExportToExcel(Control ctl)
{
Response.Clear();
Response.ContentType = "application/ms-excel";
Response.AddHeader("content-disposition", "attachment;filename=ExcelCopy.xls");
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
ctl.RenderControl(hw);
Response.Write(sw.ToString());
Response.End();
return Json(1);
}
以及 jQuery 中的以下函数:
function btnConvertToExcelClick() {
var inputParamtrs={ ????????? }
$.ajax({
type: "POST",
url: "/Expenses/ExportToExcel",
data: inputParamtrs,
success: function (json) {
}
});
return false;
}
我想我想问的是如何将整个 HTML 表作为 Control传递给 JsonResult 函数。帮助!