Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 以未定义的延迟从服务器端异步发送多个PartialView到客户端_C#_Javascript_Asp.net Mvc_Jquery_Asp.net Mvc 4 - Fatal编程技术网

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中的任何库一样。。我去看看,还有什么建议吗?不随便