2
public class SomeController : AsyncController{
    [ChildAction]
    public Task<ViewResult> DoSomething(){ ... }
} 

If I were to call the above action from inside a view of a normal controller, what would happen? e.g.

<body>
      @Html.Action("DoSomething","SomeController")
</body>

I can imagine 4 scenarios given my understanding of how async controller is implemented.

  1. It will error out because the parent controller expects an ActionResult.

  2. It will error out randomly because the action is async and the parent might have called HttpResponse.End()

  3. The Mvc framework is smart enough to realize, that the child action is returning a task, so the parent controller will continue to execute, and then wait for all the async result to return (aka thread join) before it calls the Response.End()

  4. The Mvc framework will promote the parent action to an async thread, serialize the response information and stow it away, and when the asynchronous tasks signals, rehydrate it and resume operation.

Can someone with better understanding of the framework describe, what is going on behind the scenes and tell me, if it makes sense at all to have an asynchronous child action?

tereško
  • 58,060
  • 25
  • 98
  • 150
Alwyn
  • 8,079
  • 12
  • 59
  • 107

0 Answers0