Copied to clipboard

Flag this post as spam?

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


  • Jorge Ribeiro 29 posts 213 karma points
    May 07, 2020 @ 22:55
    Jorge Ribeiro
    0

    Render grid in nested content

    Hi, pretty newbie here

    I have an umbraco 8 site with a document type that has a nested content in it. That nested content has an element composed of a color picker (backgroundColor) and a grid layout (gridLayout).

    When rendering the nested content I can't render the grid as the helper I'm used to

    Html.GetGridHtml(item, "grid") 
    

    does not work with IPublishedElement (json result of grid layout)

    Here's my code:

    var layouts = Model.Value<IEnumerable<IPublishedElement>>("layouts");
    foreach(var layoutItem in layouts) 
    {
        <div style="background-color: #@layoutItem.Value("BackgroundColor")">
            @Html.GetGridHtml(layoutItem, "gridLayout", "custom/customgridlayout")
        </div>
    }
    

    The error is at Html.GetGridHtml "cannot convert from 'Umbraco.Core.Models.PublishedContent.IPublishedElement' to 'Umbraco.Core.Models.PublishedContent.IPublishedContent'"

    I check and the result grid layout, as it appears in nested content, is json... I can get BackgroundColor, at least as a string...

    I'm sure I'm making a huge mess with this but how can I render such a grid?

    Best regards

    Jorge

  • Jorge Ribeiro 29 posts 213 karma points
    May 08, 2020 @ 09:52
    Jorge Ribeiro
    101

    I found a way!

    Instead of calling Html.GetGridHtml helper I rendered it using grid partial view

    <div style="background-color: #@layoutItem.Value("BackgroundColor")">
       @Html.Partial("grid/custom/customgridlayout", layoutItem.Value("gridLayout"))
     </div>
    

    I use a custom grid layout copied from one already existing bootstrap3.cshtml.

    Jorge

Please Sign in or register to post replies

Write your reply to:

Draft