我正在編寫一個報告工具,您可以直接在頁面上顯示報告或將其下載爲Excel文件。如果你只是想在網頁上顯示它,網站會按預期重新加載。如果它作爲excel文件下載,則下載可以正常工作,但頁面不會重新加載。這對我來說是一個問題,因爲我不知道如何在之後禁用加載動畫。下載是通過對響應對象的寫入操作完成的。下面是代碼:通過回覆文件下載後重新加載頁面
private void ExcelExport(DataTable outList)
{
ViewBag.Reload = true;
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=report.xls");
Response.ContentType = "application/ms-excel";
Response.Charset = "";
Response.Output.Write(Excel.GetXml(outList));
Response.Flush();
Response.End();
}
的代碼是從一個ActionResult方法我的控制器(其中爲ExcelExport方法也設)中調用:
public ActionResult WisPriceMatrix(string cc, string sl, string exp)
{
ViewBag.StorageLocations = this.StorageLocations;
ViewBag.WisPriceMatrixReport = null;
int cleanCode = 3;
if ((cc != null && cc != string.Empty && Int32.TryParse(cc, out cleanCode)) || (sl != null && sl != string.Empty))
{
sl = sl == string.Empty ? null : sl;
ViewBag.ParameterSl = sl;
ViewBag.ParameterCleanCode = cleanCode;
DataTable outList = dc.GetWisPriceMatrix(sl, cleanCode);
if (exp == null || exp == string.Empty || exp != "1")
{
ViewBag.WisPriceMatrixReport = outList;
}
else
{
if (outList.Count > 0)
{
this.ExcelExport(outList);
}
else
{
ViewBag.NoResults = "1";
}
}
}
return View();
}
任何想法我怎麼能強制頁面重新加載之後?
我試圖創建一個ViewBag變量,它會指示重載是neede並通過JavaScript對它做出反應,但由於頁面沒有刷新,所以這是nu成功;-)。
在這裏發佈更多的代碼誰正在調用ExcelExport方法...... ???? – 2014-08-28 11:39:06
我用相應的代碼編輯了我的問題。 – 2014-08-28 11:54:29
不能明白你想要什麼? – 2014-08-28 11:55:47