The UmbracoHelper was constructed with an UmbracoContext and the current request is not a front-end request
I'm trying to implement some custom routing following this post by Shannon. In my case I have venues stored outside of the content tree but want to offer the ability to view venues via the route /venues/venue/venue-name.
The problem I am having is in regards to UmbracoContext.PageId being null which is causing exceptions in the views that my View uses for layout.
My controller is as follows:
public class VenueController : PluginController
{
public VenueController() : this(UmbracoContext.Current)
{
}
public VenueController(UmbracoContext umbracoContext): base(umbracoContext)
{
}
public ActionResult Venue(string id)
{
var criteria = ExamineManager.Instance.DefaultSearchProvider.CreateSearchCriteria("content");
var filter = criteria.NodeTypeAlias("Venue");
if(!string.IsNullOrEmpty(id))
filter.And().Field("urlName", id);
var result = Umbraco.TypedSearch(filter.Compile()).ToArray();
return View("Venue", CreateRenderModel(result.First()));
}
private RenderModel CreateRenderModel(IPublishedContent content)
{
var model = new RenderModel(content, CultureInfo.CurrentUICulture);
//add an umbraco data token so the umbraco view engine executes
RouteData.DataTokens["umbraco"] = model;
return model;
}
}
}
The parent views contain macros which result in exceptions such as "Cannot render a macro when UmbracoContext.PageId is null." when I try to render my Venue view. Am I approaching this wrong? Have things changed since the blog post?
The UmbracoHelper was constructed with an UmbracoContext and the current request is not a front-end request
I'm trying to implement some custom routing following this post by Shannon. In my case I have venues stored outside of the content tree but want to offer the ability to view venues via the route /venues/venue/venue-name.
The problem I am having is in regards to UmbracoContext.PageId being null which is causing exceptions in the views that my View uses for layout.
My controller is as follows:
The parent views contain macros which result in exceptions such as "Cannot render a macro when UmbracoContext.PageId is null." when I try to render my Venue view. Am I approaching this wrong? Have things changed since the blog post?
The ste is running Umbraco v6.1.6.
is working on a reply...