i want to export an HTML table to excel in MVC. I have the following code in my controller:
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);
}
and the follwing function in jQuery:
function btnConvertToExcelClick() {
var inputParamtrs={ ????????? }
$.ajax({
type: "POST",
url: "/Expenses/ExportToExcel",
data: inputParamtrs,
success: function (json) {
}
});
return false;
}
I guess what im trying to ask is how to pass the whole HTML table to the JsonResult function as a Control. Help!