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¤tNodeId=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?
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 };
}
}
}
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 :-)
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:
When I try to call it like this:
/umbraco/surface/StoriesSurface/GetStories/?skip=0¤tNodeId=1065
... i get the following YSOD:
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! :-)
Oh, and I also tried creating a StoriesApiController (inheriting from the UmbracoApiController) for it, but I get the exact same YSOD :-)
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
Ps. this does not give me a YSOD:
URL: /umbraco/api/Stories/GetStories/?skip=0¤tNodeId=1065
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!
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?
is working on a reply...