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

Commit db0afd3

Browse files
committed
Got rid of the ViewData["dtgePreview"] option
Reverted back to using the querystring exclusively.
1 parent 1eb27ce commit db0afd3

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

docs/developers-guide.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ Because we treat your data as a standard `IPublishedContent` entity, that means
139139

140140
#### Rendering Alternative Preview Content
141141

142-
If your front end view is rather complex, you may decide that you want to feed the back office preview an alternative, less complex view. To do this, within your Razor view/partial, check `ViewData["dtgePreview"]` is set to true to detect being in preview mode to provide an alternative view.
142+
If your front end view is rather complex, you may decide that you want to feed the back office preview an alternative, less complex view. To do this, within your Razor view/partial, check for a querystring parameter `dtgePreview` being set to "1" to detect being in preview mode to provide an alternative view.
143143

144144
```
145145
@inherits Umbraco.Web.Mvc.UmbracoViewPage
146-
@if (ViewData["dtgePreview"] == true)
146+
@if (Request.QueryString["dtgePreview"] == "1")
147147
{
148148
// Render preview view
149149
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ protected PartialViewResult CurrentPartialView(object model = null)
5050

5151
protected override PartialViewResult PartialView(string viewName, object model)
5252
{
53-
ViewData.Add("dtgePreview", IsPreview);
54-
5553
if (IsPreview && string.IsNullOrWhiteSpace(PreviewViewPath) == false)
5654
{
5755
var previewViewPath = GetFullViewPath(viewName, PreviewViewPath);

src/Our.Umbraco.DocTypeGridEditor/Web/Extensions/HtmlHelperExtensions.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Web;
22
using System.Web.Mvc;
33
using System.Web.Mvc.Html;
4-
using Our.Umbraco.DocTypeGridEditor.Extensions;
54
using Our.Umbraco.DocTypeGridEditor.Web.Helpers;
65
using Our.Umbraco.DocTypeGridEditor.Web.Mvc;
76
using Umbraco.Core;
@@ -51,8 +50,6 @@ public static HtmlString RenderDocTypeGridEditorItem(
5150
dtgePreview = isPreview
5251
};
5352

54-
var viewData = new ViewDataDictionary() { { "dtgePreview", isPreview } };
55-
5653
// Try looking for surface controller with action named after the editor alias
5754
if (string.IsNullOrWhiteSpace(editorAlias) == false && SurfaceControllerHelper.SurfaceControllerExists(controllerName, editorAlias, true))
5855
{
@@ -93,19 +90,19 @@ public static HtmlString RenderDocTypeGridEditorItem(
9390
var fullPreviewViewPath = $"{previewViewPath}{editorAlias}.cshtml";
9491
if (ViewHelper.ViewExists(helper.ViewContext, fullPreviewViewPath, true))
9592
{
96-
return helper.Partial(fullPreviewViewPath, content, viewData);
93+
return helper.Partial(fullPreviewViewPath, content);
9794
}
9895

9996
fullPreviewViewPath = $"{previewViewPath}{content.DocumentTypeAlias}.cshtml";
10097
if (ViewHelper.ViewExists(helper.ViewContext, fullPreviewViewPath, true))
10198
{
102-
return helper.Partial(fullPreviewViewPath, content, viewData);
99+
return helper.Partial(fullPreviewViewPath, content);
103100
}
104101

105102
fullPreviewViewPath = $"{previewViewPath}Default.cshtml";
106103
if (ViewHelper.ViewExists(helper.ViewContext, fullPreviewViewPath, true))
107104
{
108-
return helper.Partial(fullPreviewViewPath, content, viewData);
105+
return helper.Partial(fullPreviewViewPath, content);
109106
}
110107
}
111108

@@ -115,29 +112,29 @@ public static HtmlString RenderDocTypeGridEditorItem(
115112
var fullViewPath = $"{viewPath}{editorAlias}.cshtml";
116113
if (ViewHelper.ViewExists(helper.ViewContext, fullViewPath, true))
117114
{
118-
return helper.Partial(fullViewPath, content, viewData);
115+
return helper.Partial(fullViewPath, content);
119116
}
120117

121118
fullViewPath = $"{viewPath}{content.DocumentTypeAlias}.cshtml";
122119
if (ViewHelper.ViewExists(helper.ViewContext, fullViewPath, true))
123120
{
124-
return helper.Partial(fullViewPath, content, viewData);
121+
return helper.Partial(fullViewPath, content);
125122
}
126123

127124
fullViewPath = $"{viewPath}Default.cshtml";
128125
if (ViewHelper.ViewExists(helper.ViewContext, fullViewPath, true))
129126
{
130-
return helper.Partial(fullViewPath, content, viewData);
127+
return helper.Partial(fullViewPath, content);
131128
}
132129
}
133130

134131
// Resort to standard partial views
135132
if (ViewHelper.ViewExists(helper.ViewContext, editorAlias, true))
136133
{
137-
return helper.Partial(editorAlias, content, viewData);
134+
return helper.Partial(editorAlias, content);
138135
}
139136

140-
return helper.Partial(content.DocumentTypeAlias, content, viewData);
137+
return helper.Partial(content.DocumentTypeAlias, content);
141138
}
142139
}
143140
}

0 commit comments

Comments
 (0)