0
我在我的MVC C#應用程序下面的代碼:返回文件相當於Web窗體
return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "PSL.xlsx");
從流返回PSL文件。我想背後做同樣的事情在我的Web窗體代碼:
Response.Clear();
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("Content-Disposition", "attachment; filename=PSL.xlsx");
Response.BinaryWrite(stream.ToArray());
// myMemoryStream.WriteTo(Response.OutputStream); //works too
Response.Flush();
Response.Close();
Response.End();
想知道這是否是因爲我收到以下錯誤消息是正確的做法:
Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}
這對我來說確實很好。你在哪裏得到這個錯誤?究竟哪條線? – HaukurHaf
運行後。我有一個返回void的方法中的代碼。這兩個相同的代碼(來自MVC的代碼還是Web窗體中的代碼?) –
這不是完全相同的代碼,但結果應該是相同的。設置一些標題,然後將二進制數據輸出到瀏覽器。這個錯誤信息對我來說沒有意義。我沒有得到正在評估的表達式。 – HaukurHaf