I am using EPiServer 7.5+ and have a scenario where some of my Local Blocks are not updating after being edited in the On Page Editing window.

I either have to do a full page refresh after editing the impacted Local Block, or use the FullRefreshPropertiesMetaData, which just refreshes the whole page anyway.

Why are some Local Blocks not refreshing correctly?

After investigating a bit I have noticed that this issue only impacts Local Blocks that have their own Controller.

Example Code

Pages / Blocks:

[ContentType("nguid")]
public class SimpleLocalBlock : BlockData{
    public virtual string Text {get;set;}
}

[ContentType("nguid")]
public class AdvancedLocalBlock : BlockData{
    public virtual string Text {get;set;}
} 

[ContentType("nguid")]
public class MyPage : PageData
{
   public virtual SimpleLocalBlock Simple {get;set;}
   public virtual AdvancedLocalBlock Advanced {get;set;}
}

Controller:

public class AdvancedLocalBlockController : BlockController<AdvancedLocalBlock>
{
    public override ActionResult Index(MultiLinksBlock currentContent)
    {
        return PartialView(ViewPath, currentContent);
    }

    //Use ViewData["Tag"] to decide which View to use
    public virtual string ViewPath
    {
        get
        {
            var tag =
                this.ControllerContext.ParentActionViewContext.ViewData["Tag"]
                        as AdvancedViews?;

            if (tag.HasValue)
            {
                switch (tag)
                {
                    case AdvancedViews.View1:
                        return "~/Views/Shared/Blocks/View1.cshtml";

                    case AdvancedViews.View1:
                        return "~/Views/Shared/Blocks/View2.cshtml";
                 }
            }

            throw new Exception("Invalid Tag.");
        }
    }

Enum for controlling which View is used:

public Enum AdvancedViews
{
    View1 = 1,
    View2 = 2
}

View (Razor) - MyPage

@model MyPage 

@Html.PropertyFor(x => x.Simple)

@Html.PropertyFox(x => x.Advanced, new {Tag = AdvancedViews.View1})

View (Razor) - SimpleLocalBlock

@model SimpleLocalBlock

@Html.PropertyFor(x => x.Text)

View (Razor) - View1

@model AdvancedLocalBlock

@Html.PropertyFor(x => x.Text)

Summary

I can use On Page Editing when editing Simple and the block will refresh correctly inline on the page (ie doesn't need to refresh entire page). But when I use On Page Editing with 'Advanced' I don't see the updates until I refresh the entire page.

Related posts

Recent Viewed