Copied to clipboard

Flag this post as spam?

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


  • Allan Kirk 9 posts 99 karma points c-trib
    Feb 21, 2019 @ 06:36
    Allan Kirk
    0

    Render grid in Umbraco 8

    I simply cannot get the grid to render in Umbraco8, and I do not know why.

    I have a page with a grid on it with the alias "contentGrid"

    I have a template file like this:

        @inherits Umbraco.Web.Mvc.UmbracoViewPage
    
    @{
        Layout = "master.cshtml";
    }
    
    @* the fun starts here *@
    
    @Html.GetGridHtml(Model.Content, "contentGrid")
    

    As documented here https://our.umbraco.com/documentation/getting-started/backoffice/property-editors/built-in-property-editors/grid-layout/render-grid-in-template

    But I get a

    'IPublishedContent' does not contain a definition for 'Content' and no accessible extension method 'Content' accepting a first argument of type 'IPublishedContent' could be found (are you missing a using directive or an assembly reference?)

    Well, maybe I am, but I do not know which one.

    I read somewhere, that I do not need to add .Content in U8, but then I get

    No property type found with alias contentGrid

    What to do?

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Feb 21, 2019 @ 07:20
    Søren Gregersen
    1

    Hi,

    You need to figure out what model you are trying to render. Umbraco is telling you that you are trying to render a model that does not have the "contentGrid" property.

    How is that view being used? What model are you passing on to it etc. ?

  • Allan Kirk 9 posts 99 karma points c-trib
    Feb 21, 2019 @ 10:53
    Allan Kirk
    100

    Okay, I was trying to make the example clearer, and stumbled upon the solution. Thanks you Søren, for prompting me to do that.

    For future reference, I was missing a line, so the correct example should look like this:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.Home>
    @using ContentModels = Umbraco.Web.PublishedModels;
    @{
        Layout = null;
    }
    @Html.GetGridHtml(Model, "contentGrid")
    

    It looks like "

  • Bjarne Fyrstenborg 1282 posts 3994 karma points MVP 8x c-trib
    Feb 21, 2019 @ 11:30
    Bjarne Fyrstenborg
    1

    Hi Allan

    Remember in Umbraco 8 the RenderModel has been removed and simplified, so there is no longer Model.Content just Model.

    I guess we now could have a property with alias content and access it using Model.Content using ModelsBuilder, which in v7 would cause collisions.

    /Bjarne

  • Semyon Vyskubov 7 posts 117 karma points
    Aug 08, 2019 @ 12:57
    Semyon Vyskubov
    0

    Thank you very much! Documentation's seems to be outdated and I've created related issue.

Please Sign in or register to post replies

Write your reply to:

Draft