Try our conversational search powered by Generative AI!

Cannot Preview Changes made on LayoutModel

Vote:
 

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.

StartPage.cs

public virtual LinkItemCollection ProductPageLinks { get; set; }

LayoutModel.cs

public LinkItemCollection ProductPages { get; set; }

PageViewContextFactory.cs

return new LayoutModel
{
     ...
     ProductPages = startPage.ProductPageLinks,
     ...
};

StartPageController.cs

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

Footer.cshtml

@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.

#122598
Jun 05, 2015 23:06
Vote:
 

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

}
#122636
Jun 08, 2015 17:54
Vote:
 

Thanks! This worked perfectly.

#122638
Jun 08, 2015 18:44
Vote:
 

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.

#122641
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.