Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Søren Kottal 713 posts 4571 karma points MVP 6x c-trib
    Oct 07, 2016 @ 13:54
    Søren Kottal
    0

    Doc Type Grid Editor and Models Builder

    Has anyone had any luck getting Doc Type Grid Editor to work with Models Builder?

    When I render my page I get this stack trace:

    Umbraco.Web.Mvc.ModelBindingException: Cannot bind source content type Our.Umbraco.DocTypeGridEditor.Models.DetachedPublishedContent to model type Umbraco.Web.PublishedContentModels.DtgeLinkGrid.
       at Umbraco.Web.Mvc.RenderModelBinder.ThrowModelBindingException(Boolean sourceContent, Boolean modelContent, Type sourceType, Type modelType)
       at Umbraco.Web.Mvc.RenderModelBinder.BindModel(Object source, Type modelType, CultureInfo culture)
       at Umbraco.Web.Mvc.UmbracoViewPage`1.SetViewData(ViewDataDictionary viewData)
       at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
       at Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer)
       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, IPublishedContent content, String editorAlias, String viewPath, String previewViewPath)
       at ASP._Page_app_plugins_doctypegrideditor_render_doctypegrideditor_cshtml.Execute() in c:\Workspaces\Web\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.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer)
       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:\Workspaces\Web\Views\Partials\Grid\Editors\Base.cshtml:line 20
    

    I saw some quick fixes at https://github.com/umco/umbraco-doc-type-grid-editor/issues/44 but I can't seem to get them working.

    My view:

    @inherits UmbracoViewPage<IPublishedContent>
    @if (Model != null)
    {
        // cast model as the correct ContentModel
        var model = new DtgeLinkGrid(Model);
    }
    
  • Frans de Jong 550 posts 1862 karma points MVP 4x c-trib
    Jan 24, 2017 @ 08:18
    Frans de Jong
    0

    What I did now as a workaround:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    
    @{
       var viewModel = null;
       if(Model != null){
           var viewModel = new DTGEModel(Model);
       }
    }
    

    Since the constructor of the modelsbuilder modal needs IPublishedContent and the Model of DTGE is IPublishedContent it works lika a charm.

  • z4kk 24 posts 83 karma points
    Apr 20, 2017 @ 13:18
    z4kk
    2

    My workaround generic class:

    public class GridViewPage<T> : UmbracoViewPage<IPublishedContent>
            where T : IPublishedContent
        {
            private T _model;
            protected new T Model => _model != null ? _model : (_model = (T) Activator.CreateInstance(typeof(T), base.Model));
    
            public override void Execute()
            {
            }
        }
    

    In partial view:

    @inherits GridViewPage<TextWithHeaderBlock>
    
    <h3>@Model.Header</h3>
    
    <p>@Model.Text</p>
    
  • nickornotto 403 posts 907 karma points
    Mar 17, 2022 @ 13:17
    nickornotto
    0

    This works great for me

Please Sign in or register to post replies

Write your reply to:

Draft