Copied to clipboard

Flag this post as spam?

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


  • suzyb 464 posts 877 karma points
    Feb 17, 2015 @ 17:32
    suzyb
    0

    Calling RenderTemplate from surface controller view

    I need to retrieve the contents of every page on the small site I'm working on and append it to the home page.  I have this almost working however am finding that the forms do not work.

    This is how I get the Html for each page to append to the home page.

    I call a surface controller from ajax like so

    $(function () {
        $.get("/umbraco/surface/homepagesurface/renderfullsite/", function (data) {
            $("#all-pg-code").append(data);
        });
    });

    The surface controller then returns a partial view

    public PartialViewResult RenderFullSite()
    {
         return PartialView("_RenderFullSite");
    }

    Which calls render template on each of the pages of the site, concatenates the HTML and outputs it.

    StringBuilder sb = new StringBuilder();
    
    foreach (var item in childNodes)
    {
        HtmlDocument htmlDoc = new HtmlDocument();
        htmlDoc.LoadHtml(Umbraco.RenderTemplate(item.Id, item.TemplateId).ToHtmlString());
    
        HtmlNode node = htmlDoc.DocumentNode.SelectSingleNode("//div[@class=\"content-container\"]");
        if (node != null)
        {
            // do some stuff to remove some html we don't need
            sb.Append(node.OuterHtml);
        }
    
    }
    @Html.Raw(sb.ToString());

    Several of the pages have a short contact form on it however when this is submitted it is being submitted to the surface controller URL (/umbraco/surface/homepagesurface/renderfullsite/) and not the home page URL.

    Can anyone advise me how I can get the forms working.

     

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies