Try our conversational search powered by Generative AI!

Cannot Preview Changes made on LayoutModel


Within the last month, our product upgraded our website to version 8.5. Due to our product situation, our header and footer have been static partial views and not actually editable. Before the version upgrade, we were going to attempt to switch the footer to an editable one but the effort didn't fit into our sprint. I still went ahead and started playing around with how to develop it and I remember not running across this issue.

Any properties on the LayoutModel.cs and the StartPage.cs do not get visually updated when their value is updated (not published) from the All Properties or GUI views. I would make the update, go to preview the page, and no changes appeared to have been made. However, if I click into an editable field from the visual view, it suddenly populates. It always correctly shows the changed content in the All Properties view.

I have the Episerver VS extension so I created a new version 8.5 project with the MVC Alloy Sample site and I see the same issue. I tried recreating the issue by removing the links in the LinkItemCollection ProductPageLinks and publish. Then added an external link as an example (href for google) and then go to preview the page, seeing an empty area. The data change is recognized as changes needing to be published All Properties view.

The following are the snippets of code that should be correctly connecting the values between the two models and then displaying correctly on the view.


public virtual LinkItemCollection ProductPageLinks { get; set; }


public LinkItemCollection ProductPages { get; set; }


return new LayoutModel
     ProductPages = startPage.ProductPageLinks,


if (SiteDefinition.Current.StartPage.CompareToIgnoreWorkID(currentPage.ContentLink)) // Check if it is the StartPage or just a page of the StartPage type.
     var editHints = ViewData.GetEditHints, StartPage>();
     editHints.AddConnection(m => m.Layout.ProductPages, p => p.ProductPageLinks);


@model IPageViewModel
@Html.PropertyFor(x => x.Layout.ProductPages)

I tried searching for this issue/solution but it appears that I'm the only one having it. Coworker expressed possible concern over server caching involved with PageContextActionFilter.

Jun 05, 2015 23:06

Yes, indeed. Even our old friend Alloy has the same issue.

Problem is with PageViewContextFactory and its CreateLayoutModel() method. Problem is that ContentLoader will give you back published version of the page and not one you are editing.

After this line:

var startPage = _contentLoader.Get<StartPage>(SiteDefinition.Current.StartPage);

Please add following lines to workaround this limitation:

if (requestContext.GetContextMode() == ContextMode.Edit)
    var repo = ServiceLocator.Current.GetInstance<IContentVersionRepository>();
    var link = repo.List(SiteDefinition.Current.StartPage).FirstOrDefault(v => v.Status == VersionStatus.CheckedOut);

    if (link != null)
        startPage = _contentLoader.Get<StartPage>(link.ContentLink);

Jun 08, 2015 17:54

Thanks! This worked perfectly.

Jun 08, 2015 18:44

However, code handles only CheckOut scenarios. You may need to add other Status checks as well, to handle cases when page is being edited by person who is approving the changes. Also other cases may be added.

Jun 08, 2015 20:59
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.