Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Luke 110 posts 256 karma points
    Feb 12, 2015 @ 12:00
    Luke
    0

    Best Way To Render Action Asynchronously

    Hi All,

    I have an action in my surface controller that is time consuming, once the data is queried the results are returned in a partial view.

    How can I load this into the template page asynchronously.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "_layout.cshtml";
    
        <div class="partialContents">
    
        </div>
    }
    

    Thanks L

  • Tobias Klika 101 posts 570 karma points c-trib
    Feb 12, 2015 @ 13:54
    Tobias Klika
    0

    You can't do this on the server. The server does only send one response, and that's returned as soon as everything is rendered. If you really want to do it async (could you eventually cache this action?), you will have to do it with AJAX.

    You can get it's content with jQuery (or something similar) with $.get or $.ajax (or similar).

    So for example:

    $.get('/umbraco/surface/YourSurface/YourAction', function (html)
    {
      // insert your html into the DOM
      $('.partialContents').html(html);
    });
    
Please Sign in or register to post replies

Write your reply to:

Draft