Skip to content
This repository was archived by the owner on Feb 10, 2024. It is now read-only.

Commit 0ebaf16

Browse files
committed
Enables InPreviewMode in the preview controller
Fixes #117
1 parent 591cc4d commit 0ebaf16

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Our.Umbraco.DocTypeGridEditor/Web/Controllers/DocTypeGridEditorApiController.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ public object GetDataTypePreValues(string dtdId)
9999
[HttpPost]
100100
public HttpResponseMessage GetPreviewMarkup([FromBody] PreviewData data, [FromUri] int pageId)
101101
{
102+
// Set DTGE's preview to be in "preview mode", (storing the original value in a temp variable for resetting it later).
103+
var inPreviewMode = UmbracoContext.InPreviewMode;
104+
UmbracoContext.InPreviewMode = true;
105+
102106
var page = default(IPublishedContent);
103107

104108
// If the page is new, then the ID will be zero
@@ -108,7 +112,7 @@ public HttpResponseMessage GetPreviewMarkup([FromBody] PreviewData data, [FromUr
108112
page = UmbracoContext.ContentCache.GetById(pageId);
109113
if (page == null)
110114
{
111-
// If unpublished, then fake PublishedContent (with IContent object)
115+
// If unpublished, then fake PublishedContent
112116
page = new UnpublishedContent(pageId, Services);
113117
}
114118
}
@@ -153,6 +157,9 @@ public HttpResponseMessage GetPreviewMarkup([FromBody] PreviewData data, [FromUr
153157
var partialName = "~/App_Plugins/DocTypeGridEditor/Render/DocTypeGridEditorPreviewer.cshtml";
154158
var markup = Helpers.ViewHelper.RenderPartial(partialName, model, UmbracoContext.HttpContext);
155159

160+
// Restore the "preview mode" to its original value
161+
UmbracoContext.InPreviewMode = inPreviewMode;
162+
156163
// Return response
157164
var response = new HttpResponseMessage
158165
{

0 commit comments

Comments
 (0)