Quick note

Workaround: On Page Editing broken after rendering a block

In patch 3 for EPiServer 7 CMS there's a nasty little bug that manifests it self on sites built using ASP.NET MVC. After rendering a block that doesn't have a controller but instead is rendered using only a partial view (which, as we know, is good for performance) other properties that are rendered using the PropertyFor method may not be editable in OPE mode.

Luckily there's an easy workaround for that, which we can use until the issue is resolved by EPiServer; create custom display templates for the types ContentData and ContentArea. Implement each display template like the original ones shipped by EPiServer, using RenderContentData and RenderContentArea, but wrap the method calls in code that stores the value of ViewContext.RouteData.Values["currentContent"] in a variable prior to invoking the method and restores it afterwards.

/Views/Shared/DisplayTemplates/ContentData.cshtml:

@using EPiServer.Web.Mvc.Html
@model EPiServer.Core.IContentData
@{
    var original = ViewContext.RouteData.Values["currentContent"];
}
@{Html.RenderContentData(Model, false);}
@{
    ViewContext.RouteData.Values["currentContent"] = original;
}

/Views/Shared/DisplayTemplates/ContentArea.cshtml:

@using EPiServer.Web.Mvc.Html
@model EPiServer.Core.ContentArea
@{
    var original = ViewContext.RouteData.Values["currentContent"];
}
@{Html.RenderContentArea(Model);}
@{
    ViewContext.RouteData.Values["currentContent"] = original;
}
Joel Abrahamsson

Joel Abrahamsson

I'm a passionate web developer and systems architect living in Stockholm, Sweden. I work as CTO for a large media site and enjoy developing with all technologies, especially .NET, Node.js, and ElasticSearch. Read more

More about EPiServer CMS