Copied to clipboard

Flag this post as spam?

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


  • awm 187 posts 376 karma points
    Nov 11, 2015 @ 20:33
    awm
    0

    Having trouble rendering grid in a template

    Hi guys,

    I'm in the process of using the grid datatype with a custom editor and I'm having trouble rendering the data on a template.

    I don't believe the custom editor is causing any problem as that seems to be working correctly and storing the data.

    I have a feeling it may be because of the way I have my page set up:

    Essentially I have a parent page, with nested 'content region' document types beneath it. These 'content regions' have a property that uses the grid data type.

    On my page template I'm trying to iterate over all the nested content regions, and render the grid data for each.

    So on my page template I have this:

    <body>
    ....
    @Html.Partial("About/ContentRegions")
    ....
    </body>
    

    And then within my partial I have the following:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @foreach (var contentRegion in Model.Content.Children.Where(cr => cr.IsVisible()))
    {
        <div class="page-content-wrap">
            <div class="text-content" id="@(contentRegion.Name.ToLower().Replace(" ", ""))">
                <!-- Main Heading -->
                <h1>@(contentRegion.GetPropertyValue<string>("mainHeading"))</h1>
    
                <!-- Sub Heading -->
                <h3>@(contentRegion.GetPropertyValue<string>("introduction"))</h3>
                <div class="underline"></div>
    
                @Html.GetGridHtml(contentRegion, "regionBodyText");
    
            </div>
            <div class="text-separator">
                <!-- Separator -->
                <hr>
                <!-- Separator -->
            </div>
        </div>
    }
    

    Hopefully this all makes sense so far and you can see I'm simply trying to render the grid data for each of my nested content regions. However when I try to view the page I receive the following error:

    Screenshot

    When I edit the 'Bootstrap3.cshtml' view and simply spit out the model, it seems to display the json string with all of the content for the grid editor ie:

    Result

    So from what I can gather, it seems the json isn't being deserialized properly for the bootstrap3 view to handle the data. It's simply treating it as a string which is why it's throwing the error.

    I don't know exactly what I've done wrong here but I have a feeling it's something to do with me having this 'content region' nested children set up. Is anyone able to point me in the right direction here?

    Thanks!

  • awm 187 posts 376 karma points
    Nov 12, 2015 @ 10:51
    awm
    0

    I also posted this up on stackoverflow and managed to find a solution. You can find it here just in case anyone else runs into the same problem:

    http://stackoverflow.com/questions/33659662/having-trouble-rendering-grid-in-a-template

Please Sign in or register to post replies

Write your reply to:

Draft