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;
}
Similar articles
- EPiServer 7 and MVC – How to customize rendering of properties
- EPiServer editing delight challenge - MVC solution
- How EPiServer's HTML helper PropertyFor works
- EPiServer and MVC – What is the view model?
- Add UIHint to an EPiServer property without affecting its editor
- EPiServer 7 – Content, Pages and Blocks
- Custom routing for EPiServer content
- Display template for images when using EPiServer CMS and ASP.NET MVC