MVC 3 Response.Flush does not work

2019-05-11 00:22发布

I have the next code of view:

@{ Layout = null; }
@Html.Raw(ViewBag.ReportHeader as string)
@{
    Response.Buffer = true;
    Response.Flush();
}
@Html.Raw(ViewBag.ReportBodyAndFoot as string)

In this scenario, I expected the header of the page to be rendered first and then the body with the footer, but the response sent the entire page.

1条回答
做个烂人
2楼-- · 2019-05-11 01:07

I have found the answer:

public ActionResult Index(DateTime from, DateTime to)
{
  PartialView("PartialViews/_ReportHeader").ExecuteResult(ControllerContext);
  Response.Flush();
  ViewBag.Report = new InHouseFarmInFarmOutReportGenerator().GenerateReport(from, to);
  return View();
}
查看更多
登录 后发表回答