Asynchronous Partial Views or Asynchronous Html.RenderAction RRS feed

  • Question

  • User1939747927 posted

    Hi Everyone,

    I have MVC view (let us call this the "MainView") that renders around 7-8 partial views.

    The partial views are rendered on the page using the Html.RenderAction method, as opposed to RenderPartial.

    This is because the action will retrieve its own data for the partial view.

    Basically i have 7-8 partial views, each with its own data & logic, which i don't want on my Main View.

    I have tried using Asyn Controler & async methods for all actions, including the Main View.. But this doesn't seem to work.

    I.e. assume each Action takes (for the partial views) around 10 seconds.

    The result is that loading the Main View takes around 70-80 seconds.

    How can i ensure the partial views are rendered asyncrhronously.

    I understand this would be difficult, cuz they are all writing to the same stream, hence this might not work.

    If not what is the other solution?

    Finally, the partial views (rendered by different actions) are all re-usable partial views - used on numerous other pages

    Please help.


    Tuesday, February 7, 2012 5:30 PM


  • User-474980206 posted

    the view is called after the async action completes. all Html.RenderAction are call in sync. the Action itself can be async, but the RenderAction call will not return until the view finishes writing to the output stream.

    1) you can go back to one async controller, and load the models async. then render the main view, and then the partials. you can create model interfaces for each partial, so the main view will not need to know which model and type each partial views needs. 

    2) use ajax, and make ajax call for the html. there main problem here is most browser limit you to 2 concurrent requests, and of course ajax is required.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 7, 2012 9:23 PM