Copied to clipboard

Flag this post as spam?

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


  • Thomas Hansen 112 posts 327 karma points
    Mar 13, 2019 @ 20:52
    Thomas Hansen
    0

    Render Grid

    Hey,

    I have some problem rendering the grid in Umbraco 8. I only have the basic out of the box from Umbraco.

    I'm using Modelbuilder.

    This is the error i'm getting

    Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Umbraco.Web.PublishedModels.Home' does not contain a definition for 'sections'
    

    * The error is "Model.sections in the bootstap3.cshtml file" *

    @if (Model != null && Model.sections != null)
    {
    var oneColumn = ((System.Collections.ICollection)Model.sections).Count == 1;
    
    <div class="umb-grid">
        @if (oneColumn)
        {
            foreach (var section in Model.sections) {
                <div class="grid-section">
                    @foreach (var row in section.rows) {
                        @renderRow(row);
                    }
                </div>
            }   
        }else { 
            <div class="row clearfix">
                @foreach (var s in Model.sections) {
                    <div class="grid-section">
                        <div class="col-md-@s.grid column">
                            @foreach (var row in s.rows) {
                                @renderRow(row);
                            }
                        </div>
                    </div>
                }
            </div>
        }
    </div>
    }
    

    Markup

    @Html.GetGridHtml(Model, "gridContent", "bootstrap3");
    

    What am I doing wrong ?

  • Thomas Hansen 112 posts 327 karma points
    Mar 15, 2019 @ 14:15
    Thomas Hansen
    0

    Anyone ? :)

  • Ikunato 8 posts 109 karma points
    Mar 15, 2019 @ 14:27
    Ikunato
    100

    This sounds like a dumb question (because I think I have approximately the same amound of knowledge as you) but what is the content of this grid ?

    I have the exact same content of your pages and this work with me...

    Also, in VS you can add a breakpoint in the Bootstrap3.cshtml, put one and check if your "Model" have "sections"

  • Frans de Jong 494 posts 1673 karma points c-trib
    Mar 15, 2019 @ 16:39
    Frans de Jong
    1

    Did you make a typo in the property alias?

  • Thomas Hansen 112 posts 327 karma points
    Mar 18, 2019 @ 19:03
    Thomas Hansen
    0

    Sorry for the late reply.

    I found the error.. really stupid one.. I testet it on the english langauge layer.. But added the content to the danish layer.. :P

    Need to wired my head around for Umbraco 8 :D !

  • Alan Mitchell 35 posts 217 karma points c-trib
    Sep 12, 2019 @ 15:27
    Alan Mitchell
    0

    I had the same error, different cause - thought I'd post a solution in case anyone else googles to here.

    I had a document type with some content already created. I added a Grid property, and added the standard line to the appropriate template.

    @Html.GetGridHtml(Model, "Grid", "Neat3")
    

    Then I added content, tested it and all looks great.

    Unfortunately, all the other pieces of content of the same type started throwing an error as per above - does not contain a definition for 'sections'

    The issue is that the Grid property is null, and GetGridHtml passes through the page Model, not the grid property, into the Partial view ... causing an exception.

    Simplest fix was to wrap the rendering statement in a test:

    @if (Model.Grid != null) {
       @Html.GetGridHtml(Model, "Grid", "Neat3")
    }
    

    It feels like the GetGridHtml or even the default rendering templates should be a bit more defensive to avoid this problem?

Please Sign in or register to post replies

Write your reply to:

Draft