【发布时间】:2014-10-22 06:04:16
【问题描述】:
我正在编写一个报告工具,您可以在其中直接在页面上显示报告或将其下载为 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 变量来指示需要重新加载并通过 JavaScript 对其作出反应,但由于页面未刷新,因此这是不成功的 ;-)。
【问题讨论】:
-
在此处发布更多代码,您正在调用 ExcelExport 方法...????
-
我已经用相应的代码编辑了我的问题。
-
不明白你到底想要什么???
-
调用此 ExcelExport 方法后,视图未重新加载。相反,它只是保持在发送响应之前的状态。但我需要它重新加载。
-
上图是你的post方法???
标签: asp.net asp.net-mvc refresh response