Copied to clipboard

Flag this post as spam?

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


  • andrew shearer 513 posts 663 karma points
    Jan 27, 2022 @ 03:49
    andrew shearer
    0

    Umbraco Forms and using Umbraco.RenderMacroAsync in a partial

    Hi - When I follow https://our.umbraco.com/Documentation/Add-ons/UmbracoForms/Developer/Rendering-Scripts/ and add the following to a page view (i.e. something that inherits UmbracoViewPage) then the form shows just fine:

    “@await Umbraco.RenderMacroAsync("renderUmbracoForm", new {FormGuid="my-guid-here", FormTheme="bootstrap3-horizontal", ExcludeScripts="1"})”
    

    But i'm using nested content and want to use this macro within the partial view representing my nested content. When i try the above code I get:

    InvalidOperationException: Cannot return the IPublishedContent because the UmbracoHelper was not constructed with an IPublishedContent.

    How can I use the same “UmbracoHelper” instance in a partial view that the page template uses?

    I tried “@inject UmbracoHelper umbraco” so far which is what gives me the error above

    Thanks

    Andrew

  • andrew shearer 513 posts 663 karma points
    Jan 27, 2022 @ 20:11
    andrew shearer
    4

    update: so rather than trying to follow the docs and use "renderUmbracoForm", I copied what the shipped "InsertUmbracoFormWithTheme" view does internally and used this to render the Umbraco form:

    @(await Component.InvokeAsync("RenderForm",new { formId = form.Id, recordId = Guid.Empty, theme = "my theme", includeScripts = false }))
    

    so should the umbraco 9 docs say to use that i wonder? Is "renderUmbracoForm" only in umbraco 9 for legacy purposes? I'm using umbraco 9.2.0 and Umbraco.Forms 9.2.1.

    Is the a clean way in umbraco 9 where you can simply show an umbraco form without using a macro? 🤞

  • Paul 184 posts 646 karma points
    Mar 24, 2022 @ 12:02
    Paul
    0

    Thanks for posting about this Andrew, I've just spent the last hour or so trying to make a blocklist view component that allows CMS users to pick an Umb Form to insert (in v9).

    Quite why this isn't in the documentation I don't know, I get it when not everything is documented on Open Source stuff, but we're paying for a license to use this!

  • Debasish Gracias 32 posts 164 karma points
    Nov 29, 2022 @ 11:29
    Debasish Gracias
    0

    Thanks for posting this Andrew. Your solution works very well.

  • 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