Sometimes on-page editing of an Episerver block or page just doesn’t make sense, and you want the editor to go directly to the all-properties view. This may be the case when you use a page or block mainly for configuration data. If you are using a preview controller, a screen like the one below will appear when the item is opened in the editor, and a view for the block or page cannot be found.
The editor will then have to switch to all-properties view manually:
The code example below shows how you can set up an interface which you can add to any page or block model class, which forces the page or block to appear directly in all-properties view in the Episerver backend.
To set the default view to all properties view you need to use a UIDescriptor. You can can make a UIDescriptor for a specific model class like so:
[UIDescriptorRegistration]
public class ForceAllPropertiesViewUiDescriptor : UIDescriptor<TrainingDetailPage>
{
public ForceAllPropertiesViewUiDescriptor()
{
DefaultView = CmsViewNames.AllPropertiesView;
}
}
But let’s say we want our code to be a little bit more generic, so we can set all-properties view as the default on any particular page or block, without having to make a separate UIDescriptor for each model class. Interfaces to the rescue!
public interface IForceAllPropertiesView
{
}
Our interface doesn’t need to do anything, we just set up the UIDescriptor for the interface instead of for a particular model class:
[UIDescriptorRegistration]
public class ForceAllPropertiesViewUiDescriptor : UIDescriptor<IForceAllPropertiesView>;
{
public ForceAllPropertiesViewUiDescriptor()
{
DefaultView = CmsViewNames.AllPropertiesView;
// From EPiServer.CMS.UI 10.11.0 Sticky View Mode was introduced.
// You can prevent editors editors
// coming back into OnPageEditView later
// if they have inadvertently chosen it during editing,
// and/or disable OnPageEditView altogether.
EnableStickyView = false;
DisabledViews = new List<string> { CmsViewNames.OnPageEditView, CmsViewNames.PreviewView };
}
}
And then we can apply this interface on any page or block model class, whenever we need:
[ContentType(DisplayName = "Training Detail Page", GUID = "a2cd7456-fe33-49ce-a697-e66fb3ccfb63", Description = "")]
public class TrainingDetailPage : PageData, IForceAllPropertiesView
{
[Display(
Name = "Header",
GroupName = SystemTabNames.Content,
Order = 10)]
public virtual string Header { get; set; }
[Display(
Name = "Intro",
GroupName = SystemTabNames.Content,
Order = 20)]
public virtual XhtmlString Intro { get; set; }
}