Copied to clipboard

Flag this post as spam?

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


  • Bo Damgaard Mortensen 712 posts 1189 karma points
    May 14, 2014 @ 13:10
    Bo Damgaard Mortensen
    0

    REST SurfaceController

    Hi all,

    I've made a small SurfaceController for an Umbraco 7.1.2 site. The SurfacController to return a JsonResult since it will be used for REST calls.

    My SurfaceController looks like this:

    public class StoriesSurfaceController : SurfaceController
    {
        private UmbracoHelper _helper = new UmbracoHelper(UmbracoContext.Current);
    
        public JsonResult GetStories(int skip, int currentNodeId)
        {                        
            return Json(StoryRepository.GetStoriesPaged(_helper.TypedContent(currentNodeId), _helper, skip, 10));
        }
    }
    

    When I try to call it like this: /umbraco/surface/StoriesSurface/GetStories/?skip=0&currentNodeId=1065

    ... i get the following YSOD:

    Cannot render a macro when there is no current PublishedContentRequest.
    

    Seems like there's some routing going nuts here? :-) I haven't made any custom routing though. Only thing I can think of is that I'm using strongly typed views and I have a StoriesController for that purpose. However, I've basically grabbed the exact same setup from an Umbraco 6.1.6 site that I made some time ago.

    Has there been any change to the way routing and (restful) SurfaceControllers works in Umbraco 7, that I don't know of?

    Thanks in advance! :-)

  • Bo Damgaard Mortensen 712 posts 1189 karma points
    May 14, 2014 @ 13:12
    Bo Damgaard Mortensen
    0

    Oh, and I also tried creating a StoriesApiController (inheriting from the UmbracoApiController) for it, but I get the exact same YSOD :-)

  • Sebastiaan Janssen 4893 posts 14612 karma points MVP admin hq
    May 14, 2014 @ 16:37
    Sebastiaan Janssen
    0

    If your trying to get nodes for paging maybe this will help: http://cultiv.nl/blog/whats-this-umbraco-route-hijacking-all-about/

    And if you have half an hour here's a really long thread you can read which mentions that same error: http://our.umbraco.org/forum/developers/extending-umbraco/41367-Umbraco-6-MVC-Custom-MVC-Route?p=3

  • Sebastiaan Janssen 4893 posts 14612 karma points MVP admin hq
    May 14, 2014 @ 16:39
    Sebastiaan Janssen
    0

    Ps. this does not give me a YSOD:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Umbraco.Web;
    using Umbraco.Web.Mvc;
    using Umbraco.Web.WebApi;
    
    namespace Umbraco.Course.Controllers
    {
        public class StoriesController : UmbracoApiController
        {
            private UmbracoHelper _helper = new UmbracoHelper(UmbracoContext.Current);
    
            [System.Web.Http.HttpGet]
            public JsonResult GetStories(int skip, int currentNodeId)
            {
                return new JsonResult() { Data = _helper.TypedContent(currentNodeId).Id, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
            }
        }
    }
    

    URL: /umbraco/api/Stories/GetStories/?skip=0&currentNodeId=1065

  • Bo Damgaard Mortensen 712 posts 1189 karma points
    May 14, 2014 @ 22:32
    Bo Damgaard Mortensen
    0

    Hiya Sebastiaan,

    Thanks a lot for your reply :-)

    I've read both links now and did some more testing. I even went so far as to create a Generic Handler to test if it was really something to do with routing. Still got the exact same error.

    I then started to comment each and every line in my StoryRepository (bascially a static class that maps IPublishedContent to custom models) and the error disappeared when I commented out the body text property, which is a RTE. Then it hit me: the RTE contains a macro (a very simple one which outputs some markup/text). Once I deleted the macro in the RTE property it worked fine.

    Now, I'm just glad that I don't need the body text property in the JSON output :-D Pretty lucky.

    I'm still curious about why it gives me a YSOD, though. Granted, the macro contains a parameter which is a Content Picker, so I guess that has something to do with it :-)

    Thanks again!

  • Jeric 122 posts 192 karma points
    Oct 08, 2014 @ 19:07
    Jeric
    0

    having the same issue when there's a macro within the RTE. Any way we can strip out the macro when using the REST call with UmbracoApiController?

Please Sign in or register to post replies

Write your reply to:

Draft