Umbraco当没有当前的PublishedContentRequest时,无法呈现宏

时间:2015-06-01 06:53:16

标签: c# asp.net-mvc umbraco

希望你能帮助我。我在使用RenderMvcController从我的umbraco razor页面调用一个视图时遇到了这个错误。它似乎无法在布局页面中渲染我创建的宏。

第4行:} 第5行:
第6行:@ Umbraco.RenderMacro(" ExternalRedirect") 第7行:
第8行:

源文件:c:\ Working \ Git \ ID \ UMB Packages \ Website \ Views \ Default.cshtml Line:6

堆栈追踪:

  

[InvalidOperationException:当没有宏时无法呈现宏   当前PublishedContentRequest。]
  Umbraco.Web.UmbracoHelper.RenderMacro(String alias,IDictionary 2 parameters) +142 ASP._Page_Views_Default_cshtml.Execute() in c:\Working\Git\ID\UMB Packages\Website\Views\Default.cshtml:6
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +125
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +196
System.Web.WebPages.WebPageBase.Write(HelperResult result) +89
System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action
1 body)+233
  System.Web.WebPages.WebPageBase.PopContext()+287
  Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext,   TextWriter作家)+140
  System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)   +378 System.Web.Mvc。<> c__DisplayClass1a.b__17()   +33 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter   filter,ResultExecutingContext preContext,Func 1 continuation) +799724 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func 1 continuation)   +799724 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext   controllerContext,IList`1过滤器,ActionResult actionResult)+263
  System.Web.Mvc.Async<> c__DisplayClass25.b__22(IAsyncResult的   asyncResult)+787092
  System.Web.Mvc<> c__DisplayClass1d.b__18(IAsyncResult的   asyncResult)+28
  System.Web.Mvc.Async<> c__DisplayClass4.b__3(IAsyncResult的   ar)+15 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult   asyncResult)+65
  System.Web.Mvc.Async<> c__DisplayClass4.b__3(IAsyncResult的   ar)+15 System.Web.Mvc.Controller.EndExecute(IAsyncResult   asyncResult)+51
  System.Web.Mvc<> c__DisplayClass8.b__3(IAsyncResult的   asyncResult)+42
  System.Web.Mvc.Async<> c__DisplayClass4.b__3(IAsyncResult的   ar)+15 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult)   asyncResult)+51
  System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()   +606 System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously)+288

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;
    }
}

0 个答案:

没有答案