Try our conversational search powered by Generative AI!

Blocks accessed outside of PageControllers don't render until PageController hit


This behavior is reproducable, if somewhat difficult to explain.

I have an existing MVC site, in to which I'm trying to add EPiServer.  None of my existing controllers inherit from IRenderTemplate<T>, only my new EPiServer pages.   My site start page is now an EPiServer page, which often links to pre-existing, non-MVC controllers.

To mix the two worlds, both the EPiServer (IRenderTemplate<T>) controllers, and my pre-existing controllers use the same _Layout.cshtml.  That file grabs a static reference to the StartPage, then renders the blocks (like header, footer, and navigation).  In this way, the content for the header/footer is controlled/editable by EPiServer, even for the pre-existing controllers, and can be edited by editing the Start Page in EPiServer.

The code in my _Layout.cshtml file looks like the following:.


StartPage startPage = layoutViewModel.ContentRepository.Get<Mosaic.Models.Pages.StartPage>(EPiServer.Core.ContentReference.StartPage);       




Here is where the trouble starts.  If I access one of my pre-exising controllers *first*, the block isn't rendered.  No errors, just nothing is output.  The "blank area" will persist until I visit a controller that *does* implement IRenderTemplate<T>, at which point, the header will display appropriately everywhere.

Is there a work around for this, so I can ensure the block will always render despite the load order?

May 21, 2013 18:42

One guess is that something in PropertyFor will look for the currently routed content. In the case when the routing is for your non-episerver controller that routed content will not be set and hence nothing is outputed by PropertyFor.

If that is the case you could set the routed content link in your controller, something like (using namespace EPiServer.Web.Routing):

if (ContentReference.IsNullOrEmpty(ControllerContext.RequestContext.GetContentLink()))

May 22, 2013 9:40

Unfortunately, this doesn't seem to resolve the issue.  I tried adding this to the OnActionExecuting method of the non-EPiServer controller, and it doesn't seem to change the behavior.

May 28, 2013 22:10

Anyone else have ideas on this?  Surely I'm not the only one merging controllers like this?

Jun 05, 2013 17:05
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.