2014-08-28 93 views
0

我正在编写一个报告工具,您可以直接在页面上显示报告或将其下载为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成功;-)。

+0

在这里发布更多的代码谁正在调用ExcelExport方法...... ???? – 2014-08-28 11:39:06

+0

我用相应的代码编辑了我的问题。 – 2014-08-28 11:54:29

+0

不能明白你想要什么? – 2014-08-28 11:55:47

回答

0

在你的情况下,为了重新加载页面要么你可以使用Viewbag并设置Viewbag值控制器上说Viewbag.data="reload",然后在视图检查Viewbag作为

$(document).ready(function(){ 
    if('@Viewbag.data' == "reload") 
    { 
    window.location.reload(true); 
    } 
}); 

或者你可以只是代替return View()使用return RedirectToAction("WisPriceMatrix")RedirectToAction创建一个新的http(302)请求并重新加载页面。

+0

我已经尝试了类似于第一个建议somethig。但是这不起作用,因为该站点未被重新加载,因此脚本不会再次执行。我刚刚尝试了第二个不起作用的建议。到达命令'return RedirectToAction(“WisPriceMatrix”);',但对结果没有影响。 – 2014-08-28 12:15:57

+0

@RomanoZumbé...第二个答案肯定会出手工作...只是检查你的httpget和httppost控制器的行为有名称“WisPriceMatrix”.. ?? – 2014-08-28 12:18:51

+0

控制器Action被命名为“WisPriceMatrix”,但我认为在手动编辑响应之后,“RedirectToAction”方法的行为与预期不符。 – 2014-08-28 12:30:20

相关问题