Pages

Thursday, 4 June 2020

DocTypeGridEditor - partial view was not found

We've been working with DocTypeGridEditor for years, but just once in a while, there's an issue that takes more than 5 minutes to isolate.

I'm going to assume you know what I'm talking about, for an intro to DTGE will take too much time and can be found elsewhere.

Below is the popup that the users get when adding a control to the grid.


Embed, Image, Macro and Rich text are there by default. Headline and Quote is something we replaced in our base project. Widget is something specific for the project I'm working on.

The problem is the "Doc Type" option. It's not configured in the grid.editors.config.js where you control which controls the editors can pick. It must be added behind the scenes by the DTGE implementation somehow.

For some reason, however, if one of our editors picked "Doc Type" instead of one of the others, it yields the following error:
System.InvalidOperationException: The partial view 'richTextBlock' was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/ContentPage/richTextBlock.aspx
~/Views/ContentPage/richTextBlock.ascx
~/Views/Shared/richTextBlock.aspx
~/Views/Shared/richTextBlock.ascx
~/Views/ContentPage/richTextBlock.cshtml
~/Views/ContentPage/richTextBlock.vbhtml
~/Views/Shared/richTextBlock.cshtml
~/Views/Shared/richTextBlock.vbhtml
~/Views/Partials/richTextBlock.cshtml
~/Views/MacroPartials/richTextBlock.cshtml
~/Views/richTextBlock.cshtml
   at System.Web.Mvc.HtmlHelper.FindPartialView(ViewContext viewContext, String partialViewName, ViewEngineCollection viewEngineCollection)
   at System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection)
   at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData)
   at Our.Umbraco.DocTypeGridEditor.Web.Extensions.HtmlHelperExtensions.RenderDocTypeGridEditorItem(HtmlHelper helper, IPublishedElement content, String editorAlias, String viewPath, String previewViewPath, Boolean isPreview)
   at ASP._Page_app_plugins_doctypegrideditor_render_doctypegrideditor_cshtml.Execute() in C:\Projects\DPW\Website\ProjectV8.Site\app_plugins\doctypegrideditor\render\doctypegrideditor.cshtml:line 28
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
   at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at Umbraco.Web.Mvc.ProfilingView.Render(ViewContext viewContext, TextWriter writer) in d:\a\1\s\src\Umbraco.Web\Mvc\ProfilingView.cs:line 25
   at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData)
   at ASP._Page_Views_Partials_grid_editors_base_cshtml.Execute() in C:\Projects\DPW\Website\ProjectV8.Site\Views\Partials\grid\editors\base.cshtml:line 20

Using the richTextBlock directly works fine, so after some head-scratching I discovered that we usually declare our components as follows:
  {
    "name": "Headline",
    "alias": "headline",
    "view": "/App_Plugins/DocTypeGridEditor/Views/doctypegrideditor.html",
    "icon": "icon-coin",
    "render": "/App_Plugins/DocTypeGridEditor/Render/DocTypeGridEditor.cshtml",
    "config": {
      "allowedDocTypes": [
        "headlineBlock"
      ],
      "nameTemplate": "",
      "enablePreview": true,
      "viewPath": "/Views/Partials/Grid/Editors/",
      "previewViewPath": "/Views/Partials/Grid/Editors/",
      "previewCssFilePath": "",
      "previewJsFilePath": ""
    }
  }
Some debugging showed me that the "Doc Type" definition, which is added automatically, even if you want it or not, is this:
  {
    "name": "Doc Type",
    "alias": "docType",
    "view": "/App_Plugins/DocTypeGridEditor/Views/doctypegrideditor.html",
    "render": "/App_Plugins/DocTypeGridEditor/Render/DocTypeGridEditor.cshtml",
    "icon": "icon-item-arrangement",
    "config": {
      "allowedDocTypes": [],
      "nameTemplate": "",
      "enablePreview": false,
      "viewPath": "/Views/Partials/Grid/Editors/DocTypeGridEditor/",
      "previewViewPath": "/Views/Partials/Grid/Editors/DocTypeGridEditor/Previews/",
      "previewCssFilePath": "",
      "previewJsFilePath": ""
    }
  }
The difference is the viewPath-property, ending in /DocTypeGridEditor/, which we do not have. Historical reasons, I guess.

The only way to override this default behavious is by manually adding the DocType configuration to the grid.editors.config.js, with the correct path of course.

Now, if I find a way to eliminate the Doc Type option altogether, I'll let you know.

No comments:

Post a Comment