C# 以未定义的延迟从服务器端异步发送多个PartialView到客户端
我已经潜伏了大约一个小时,试图找到一个解决方案或模式来做它(标题参考)。。 让我举个例子来说明我的意思:C# 以未定义的延迟从服务器端异步发送多个PartialView到客户端,c#,javascript,asp.net-mvc,jquery,asp.net-mvc-4,C#,Javascript,Asp.net Mvc,Jquery,Asp.net Mvc 4,我已经潜伏了大约一个小时,试图找到一个解决方案或模式来做它(标题参考)。。 让我举个例子来说明我的意思: Client-to-Server: Hey, I want information about "ww2" //using jquery's ajax .post() method Server-to-Client: Ok, got your request, prepare to receive data asynchronously. Server-to-Client: "World W
Client-to-Server: Hey, I want information about "ww2" //using jquery's ajax .post() method
Server-to-Client: Ok, got your request, prepare to receive data asynchronously.
Server-to-Client: "World War II happen in 1939 to 1945"
//after couple of seconds
Server-to-Client: "The Alliance won the war."
//some more delay
Server-to-Client: "bla bla bla"
Server-to-Client: "thats it, im done for now".
现在很明显,客户机将在使用jquery收到数据后立即显示数据。
我的主要问题是,如何在服务器上的操作上调用HttpPOST
,并异步返回多个PartialView
s
如果对样品有任何其他方法/想法,我们将不胜感激。使用信号器是一种选择
但是,如果您不想从Controller
继承您的controllers类,而是想从AsyncController
继承它。
从AsyncController
继承的控制器可以处理异步请求,并且它们仍然可以为同步操作方法提供服务
public class HomeController : AsyncController
{
public void ExtensiveTaskActionAsync()
{
AsyncManager.OutstandingOperations.Increment();
Task.Factory.StartNew(() => DoExtensiveTask());
}
private void DoExtensiveTask()
{
Thread.Sleep(5000); // some task that could be extensive
AsyncManager.Parameters["message"] = "hello world";
AsyncManager.OutstandingOperations.Decrement();
}
public ActionResult ExtensiveTaskActionCompleted(string message)
{
//task complete so, return the result
return View();
}
}
你写这篇文章的时候,就好像每个接触过计算机的人都必须知道javascript中的任何库一样。。我去看看,还有什么建议吗?不随便