Copied to clipboard

Flag this post as spam?

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


  • Rizwan ahmed Butt 5 posts 25 karma points
    Mar 05, 2015 @ 10:09
    Rizwan ahmed Butt
    0

    Problem retrieving published contents using UmbracoApiController

    Hi Everyone,

    I'm using Umbraco Version 7.2.2 and I'm trying to create a Controller class inhering from UmbracoApiController to retrieve published contents from Umbraco. I'm getting 2 problems

    1. When retrieving published contents from RTE and there's macro interested into then found the exception "Cannot render a macro when there is no current PublishedContentRequest." I've read too many thread with same error but unable to find any solution. Some people said that in Umbraco V7.2 there'll be option to insert or create PublishedContentRequest instance. Someone plesae guide me to do this?
    2. Secondly, I want a machnism to pass my paramter with PublishedContentRequest class to set the macro paramter. e.g. there's a paramter for macro parital  view name id and I want to pass this value so that appropriate patial view(s) use this parameter value by accessing Model.MacroParameters["id"]. How can I achieve this?
    Thanks in advance

    Regards,
    /Rizwan

     

  • Rizwan ahmed Butt 5 posts 25 karma points
    Mar 13, 2015 @ 06:57
    Rizwan ahmed Butt
    0

    It's almost a week to post this query on umbraco forum but unable to find any reply ;(

    Now spending time to see several solutions and workarounds to this I'm finally moving toward creating a Contrller inherted from SurfaceController and there will a [HttpGet] method named GetContents(). Now moving towards SurfaceController provides me facility to instantiate PublishContentRequest instance by using ActionAtribute (inherit this attribute from EnsurePublishedContentRequestAttribute class.

    Steps will be as follows

    1. Make call to main method GetContents() (with parameters if any).
    2. Get Contents from Umbraco UmbracoContext.ContentCache.GetById(contentId) 
    3. Check if UmbracoContext.PublishedContentRequest == null. if yes, use return RedirectToAction("CreatePublishedContentRequest", new { parameter1 });
    4. CreatePublishedContentRequest method will be decoraded with Action attributed inertied from EnsurePublishedContentRequestAttribute class
    5. override ConfigurePublishedContentRequest method of ActionAttribute and return back to old method call return RedirectToAction("GetContents", new { parameter1 });
    6. Now used PublishedContentRequest istance (use session to save PublishedContentRequest istance created through ConfigurePublishedContentRequest metod) and assign it to UmbracoContext.PublishedContentRequest
    For code and more detail you can see following thread
    https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/57240-UmbracoApiController-accessing-RTE-with-Macro-Error

    Now I've some questions using this technique

    I want to avoid making Redirect call to 2nd action (back and forth). Either there's some solution to skip this overhead? Like if I'm using same attribute to main calling method GetContetns it is not working (not invoked).

    Any help in this regard will be highly appreciable. 

    /Rizwan 
Please Sign in or register to post replies

Write your reply to:

Draft