0

在显示视图的主要部分后,如何将输出添加到 ASP.NET 视图?如果你愿意的话,有点“实时”。以下类型的作品,因为我在睡眠之间立即获得每一行输出,但在页面顶部输出所有 Response.Write 测试,而不是在最后作为整体布局中已绘制视图的一部分。而且我直到消息之后才绘制主视图数据。我看过类似的问题,SignalR 似乎有点矫枉过正,我不需要轮询,我只想添加一些即时输出,因为我在通常需要大约 30 秒的时间内想出了它,但想绘制其余部分首先查看,以便在生成时将输出附加到末尾。想法赞赏。谢谢。

这是我的控制器:

    [HttpGet]
    public ActionResult MyView()
    {
        return View();
    }

这是我的观点:

@{Layout = "~/Views/Shared/_SplitterLayout.cshtml";}

@using (Html.BeginForm())
{
  <div class="Clear">
      <p>This rest of this page should show loading data from Excel as it happens.</p>
  </div>
  <div>
      @Html.Partial("MyPartialView")
  </div>
}

这是我的部分视图:

@{
Response.Flush();
Response.Write("<br/>Started.");
Response.Flush();

Response.Write("<br/>Waiting 2 seconds...");
Response.Flush();
System.Threading.Thread.Sleep(2000);

Response.Write("<br/>Waiting 2 seconds...");
Response.Flush();
System.Threading.Thread.Sleep(2000);

Response.Write("<br/>Finished.");
Response.Flush();

}

4

1 回答 1

1

Output as much of the view as you can immediately.

Use AJAX to ask for the long-loading data and write the output using JavaScript client-side.

There are plenty of frameworks that can help you do this. You can even have the AJAX request load a partial view and just write the response to the contents of a div.

于 2013-09-09T23:16:44.380 回答