Copied to clipboard

Flag this post as spam?

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

  • mark firth 31 posts 74 karma points
    Dec 09, 2014 @ 14:11
    mark firth

    Render Macro in UmbracoApiController


    I have an application 7.2 that from in UmbracoApiController im trying to pull content from umbraco. One of the fields is a rich text editor that contains a macro. When i try pass the value of the property to my model i get the following error.

    Cannot render a macro when there is no current PublishedContentRequest.

    So the question is how do i ensure there is  a current PublishedContentRequest in the UmbracoApiController?

    My routes in the applicationStart are:

                // initialise routes
                name: "bfoapi",
                routeTemplate: "api/v1/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }

    Any help much appreciated.












  • Dave Woestenborghs 3431 posts 11702 karma points MVP 7x admin c-trib
    Dec 10, 2014 @ 13:57
    Dave Woestenborghs

    Look at this post :

    And then in the reply from Shannon. Never tried this before so don't know if it's going to work.

    Maybe you can update us on your progress


  • mark firth 31 posts 74 karma points
    Dec 12, 2014 @ 18:14
    mark firth

    Hi Dave,

    Thanks for the reply. I've not got this to work yet. From the link it looks like the same issue.

    From the post:

    "Use theNode.GetProperty("bodyContent").Value; - IIRC this does not use value converters and will return the raw string"

    Does not work.

    "Lastly, the better way to deal with this would just be to create a PublishedContentRequest, but that isn't a public API until 7.2:"

    I've downloaded the source for 7.2 and i cannot see how i can create a PublishedContentRequest. Heres the public constructor

            public PublishedContentRequest(Uri uri, RoutingContext routingContext)
                if (uri == null) throw new ArgumentNullException("uri");
                if (routingContext == null) throw new ArgumentNullException("routingContext");

                Uri = uri;
                RoutingContext = routingContext;

                _engine = new PublishedContentRequestEngine(this);

                        RenderingEngine = RenderingEngine.Unknown;

    However i dont know how to provide the routingContext as its constructor is marked as internal. Any ideas how to provide this?




  • Rizwan ahmed Butt 5 posts 25 karma points
    Mar 05, 2015 @ 13:15
    Rizwan ahmed Butt

    Hi Mark,

    I'm facing the same issue. Are you able to find some solution for this problem?


  • mark firth 31 posts 74 karma points
    Mar 17, 2015 @ 08:43
    mark firth

    Hi Rizan,

    Sorry for the late reply. No i did not get it to work - actually i had some tight deadlines and went around the problem. But i would be very intrested if anyone can get this to work with an examlpe also.



  • andrew shearer 483 posts 605 karma points
    Mar 20, 2015 @ 05:00
    andrew shearer

    anyone resolve this?

  • Michael Osborn 2 posts 71 karma points
    Sep 28, 2017 @ 22:28
    Michael Osborn

    Hey Guys, I understand that this is mega late in the game but this is how I am getting around the issues ( be gentle with me its my first post )

    var umbracoHelper = new UmbracoHelper(UmbracoContext);
    var page = umbracoHelper.Content( Id );
    UmbracoContext.PublishedContentRequest = 
                    new PublishedContentRequest(url,  UmbracoContext.RoutingContext);
     var publishedContent = UmbracoContext.PublishedContentRequest.PublishedContent;

    I have a form macro in content that I tested this with and it seems to render it just fine.

    Id = Id of content url = Uri of content that I make up from page and Request.RequestUri

Please Sign in or register to post replies

Write your reply to: