title: Umbraco Cannot render a macro when there is no current PublishedContentRequest
body: <p>Hope you can help me.I encountered that error upon calling a view from my umbraco razor page using RenderMvcController. It's seems it can't render my created macro inside a layout page.</p>
  
  <p>Line 4:  }
  Line 5:<br>
  Line 6:  @Umbraco.RenderMacro("ExternalRedirect")
  Line 7:<br>
  Line 8:  </p>
  
  <p>Source File: c:\Working\Git\ID\UMB Packages\Website\Views\Default.cshtml    Line: 6 </p>
  
  <p>Stack Trace: </p>
  
  <blockquote>
    <p>[InvalidOperationException: Cannot render a macro when there is no
    current PublishedContentRequest.]<br>
    Umbraco.Web.UmbracoHelper.RenderMacro(String alias, IDictionary<code>2
    parameters) +142    ASP._Page_Views_Default_cshtml.Execute() in
    c:\Working\Git\ID\UMB Packages\Website\Views\Default.cshtml:6<br>
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280<br>
    System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +125<br>
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext
    pageContext, TextWriter writer, WebPageRenderingBase startPage) +196<br>
    System.Web.WebPages.WebPageBase.Write(HelperResult result) +89<br>
    System.Web.WebPages.WebPageBase.RenderSurrounding(String
    partialViewName, Action</code>1 body) +233<br>
    System.Web.WebPages.WebPageBase.PopContext() +287<br>
    Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext,
    TextWriter writer) +140<br>
    System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
    +378    System.Web.Mvc.&lt;>c__DisplayClass1a.b__17()
    +33    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter
    filter, ResultExecutingContext preContext, Func<code>1 continuation)
    +799724    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter
    filter, ResultExecutingContext preContext, Func</code>1 continuation)
    +799724    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext
    controllerContext, IList`1 filters, ActionResult actionResult) +263<br>
    System.Web.Mvc.Async.&lt;>c__DisplayClass25.b__22(IAsyncResult
    asyncResult) +787092<br>
    System.Web.Mvc.&lt;>c__DisplayClass1d.b__18(IAsyncResult
    asyncResult) +28<br>
    System.Web.Mvc.Async.&lt;>c__DisplayClass4.b__3(IAsyncResult
    ar) +15    System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult
    asyncResult) +65<br>
    System.Web.Mvc.Async.&lt;>c__DisplayClass4.b__3(IAsyncResult
    ar) +15    System.Web.Mvc.Controller.EndExecute(IAsyncResult
    asyncResult) +51<br>
    System.Web.Mvc.&lt;>c__DisplayClass8.b__3(IAsyncResult
    asyncResult) +42<br>
    System.Web.Mvc.Async.&lt;>c__DisplayClass4.b__3(IAsyncResult
    ar) +15    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult
    asyncResult) +51<br>
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
    +606    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +288</p>
  </blockquote>
  
  <pre><code>public class BlogController : RenderMvcController
  {
     public BlogController()
         : this(UmbracoContext.Current)
     {
     }
  
     public BlogController(UmbracoContext umbracoContext)
         : base(umbracoContext)
     {
     }
  
     public ActionResult Index(int id)
     {
         return View("12321");
     }
  
     public ActionResult YearPost(int id)
     {
         string test = "Blog";
         var criteria = ExamineManager.Instance.DefaultSearchProvider.CreateSearchCriteria("content");
         var filterBlogs = id == 0 ? criteria.NodeTypeAlias("Blog") : criteria.NodeName("Blog");
         var result = Umbraco.TypedSearch(filterBlogs.Compile()).ToArray().First();
  
         var renderModel = CreateRenderModel(result);
         string viewBlog = "BlogPostPage";
         return View(viewBlog, renderModel);
     }
     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;
         RouteData.DataTokens["umbraco-doc-request"] = UmbracoContext.PublishedContentRequest;
         RouteData.DataTokens["umbraco-context"] = UmbracoContext;
         return model;
      }
  }
  </code></pre>