私はHTMLテーブルからデータを取得するため、クライアント側で、次のコードを持っているし、ページメソッドを介してサーバに送信:エクスポートHTML表
function dtExportToCSV(dataTable) {
var elements = dtDataToJSON(dataTable);
var headers = dtHeadersToJSON(tableSelector);
jQuery.ajax({
type: "POST",
url: "Report.aspx/exportToCSV",
data: "{'elements': " + elements + ", 'headers': " + JSON.stringify(headers) + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
if (msg.d) {
} else {
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(xhr.statusText);
}
});
}
その後、私は使用して取得したデータをCSVファイルにエクスポートするには、サーバー側の次のコードを使用します。
/// <summary>
///
/// </summary>
/// <param name="elements"></param>
/// <param name="headers"></param>
[WebMethod(EnableSession=true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static bool exportToCSV(List<object> elements, List<string> headers)
{
try
{
string attachmentType = "attachment; filename=ShortageReport.csv";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("content-disposition", attachmentType);
HttpContext.Current.Response.ContentType = "text/csv";
HttpContext.Current.Response.AddHeader("Pragma", "public");
writeHeadersInfo(headers);
HttpContext.Current.Response.End();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return false;
}
しかし、私はこのexpcetion取得:コードが最適化またはネイティブフレームがコールスタックの一番上にあるされているため、式を評価することができませんを。
誰もこの問題を処理する方法を知っていますか?
ご協力いただければ幸いです。 ありがとうございました!
〜エダーキノン
例外はどの回線から来ましたか? – Ender