PEIYANGXINQU

 

MVC异步控制器加载一个网页的所有内容

 1     public void PageAsync() {
 2 
 3             AsyncManager.OutstandingOperations.Increment();
 4 
 5             WebRequest req = WebRequest.Create("http://www.asp.net");
 6             req.BeginGetResponse((IAsyncResult ias) => {
 7                 WebResponse resp = req.EndGetResponse(ias);
 8 
 9                 string content = new StreamReader(resp.GetResponseStream()).ReadToEnd();
10                 AsyncManager.Parameters["html"] = content;
11                 AsyncManager.OutstandingOperations.Decrement();
12 
13             }, null);
14         }
15 
16         public ContentResult PageCompleted(string html) {
17 
18             return Content(html, "text/html");
19         }
View Code
 
view中的代码:
1 @model string
2 @{
3     ViewBag.Title = "Data";
4 }
5 Data: @Model
View Code

 

posted on 2013-11-25 20:28  PEIYANGXINQU  阅读(270)  评论(1编辑  收藏  举报

导航