想象一下,我们在控制器中定义了异步操作:
public class PortalController : AsyncController {
public void NewsAsync(string city) {
AsyncManager.OutstandingOperations.Increment();
NewsService newsService = new NewsService();
newsService.GetHeadlinesCompleted += (sender, e) =>
{
AsyncManager.Parameters["headlines"] = e.Value;
AsyncManager.OutstandingOperations.Decrement();
};
newsService.GetHeadlinesAsync(city);
}
public ActionResult NewsCompleted(string[] headlines) {
return View("News", new ViewStringModel
{
NewsHeadlines = headlines
});
}
当我从浏览器中调用它时 - 一切正常。但我想从另一个同步控制器调用此动作(新闻)。有没有办法调用行动并获得结果?
答案 0 :(得分:0)
public class PortalController: Controller {
public ActionResult News(string city) {
NewsService newsService = new NewsService();
ViewStringModel headlines = newsService.GetHeadlines(city);
return View(headlines);
}
}
你应该查看code you got From MSDN的其余内容,如果没有某种ActionResult来获取数据,你就无法拥有一个视图。