Copied to clipboard

Flag this post as spam?

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


  • Martin Jørgensen 1 post 71 karma points
    Jan 03, 2016 @ 21:56
    Martin Jørgensen
    0

    Problem using Umbraco 7.3 with Vorto extension and Grid data type

    Hi

    I am not able to render the Grid, if the grid is wrapped in a Vorto (language extension) data type.

    I am able to render the "content2", which is just the "grid data type":

    @Html.Partial("Grid/bootstrap3", Model.Content.GetPropertyValue("content2"))
    

    but I am not able to render the "content", which is a Vorto wrapped "grid data type":

    @Html.Partial("Grid/bootstrap3", Model.Content.GetVortoValue("content"))
    

    What am I doing wrong?

    BTW: Is it possible to get/edit/copy the RAW data of a grid - just like it is possible to switch the rich text editor from html codes to text?

    Best regards, Martin

  • Alex 1 post 71 karma points
    Mar 24, 2016 @ 16:29
    Alex
    0

    Hi Martin,

    Did you solve this? I am having the same problem.

    Cheers

  • Craig100 1136 posts 2523 karma points c-trib
    Oct 21, 2017 @ 01:17
    Craig100
    0

    I'd love to know the answer to this one. With Umb7.7.3 and latest Vorto, in template: @Html.Raw(Model.GetVortoValue("content")) is putting out a big block of JSON. Content is a Vorto wrapped grid layout.

    Any advice appreciated.

    --Craig

  • Mario Lopez 168 posts 952 karma points MVP 3x c-trib
    Oct 21, 2017 @ 05:59
    Mario Lopez
    0

    This should work.

    Html.RenderPartial("Grid/Bootstrap3", Model.Content.GetVortoValue("vortoGrid"));
    

    Craig100, the grid data is indeed just JSON so it you display it with Html.Raw... well, you'll get a JSON string.

    Martin, that line above is working for me. Are you getting any errors, or it's just blank?

  • Craig100 1136 posts 2523 karma points c-trib
    Oct 21, 2017 @ 09:16
    Craig100
    0

    Thanks, but it's not a partial it's just a grid I'm trying to render in a view. I tried with and without @Html.Raw and the only difference was the formatting of the content sections, it renders JSON no matter what.

    Anyway, just in case, I tried your suggested line and got a YSOD with "Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'Content'" So removed ".Content" but as expected VS complains "cannot implicitly convert type 'void' to 'object'.

    The View is just:-

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @using Our.Umbraco.Vorto.Extensions;
    @{
        Layout = "Master.cshtml";
    }
    
    <div class="shadow">
        @Model.GetVortoValue("bodyText");
    </div>
    

    I changed the property from "content" to "bodyText" in case I'd hit a ModelsBuilder reserved word. However, the results were just the same. Full page of unformatted JSON.

  • Mario Lopez 168 posts 952 karma points MVP 3x c-trib
    Oct 21, 2017 @ 10:36
    Mario Lopez
    2

    I see. You have a big misunderstanding here I think :)

    When you use the grid editor, the value saved in your property is not HTML. What it's saved is a JSON object that contains all the information that represents the grid, like the rows, columns, theirs contents, type of editors used...

    So if you try to display your property content it just shows that JSON string, which is exactly what you are seeing.

    The grid editor used a partial view stored on ~/Views/Partials/Grid/ In that folder you have, and you can create, partial views which only goal is to get all that JSON object and 'translate' it into proper HTML. You have Bootstrap2.cshtml or Bootstrap3.cshtml.

    To render the grid in the normal way you should use something like:

    @Html.GetGridHtml(Model.Content, "bodyText", "Bootstrap2")
    

    That helper with take the value of your bodyText and wil pass it to that partial view indicated by the last property, Bootstrap2 in this example.

    In the case of Vorto, the value of the property will still be JSON but with the structure of a Vorto object, which contains the different values for the properties on each different language. And because this JSON doesn't represent the grid we can't use the GetGridHtml helper.

    Instead we have to use the Bootstrap2 partial view manually, without helpers. So we would take the value of the Vorto property like:

    var gridObject = Model.Content.GetVortoValue("vortoGrid");
    

    This will return the value of the Vorto object in regards to the current displayed language. You have to use the GetVortoValue extension for this.

    Now that gridObject will contain a JSON string representing our grid for the language. That value has to be passed to the grid partial view to be rendered:

    @Html.Partial("Grid/Bootstrap3", gridObject);
    

    I hope it makes sense.

  • Craig100 1136 posts 2523 karma points c-trib
    Oct 21, 2017 @ 10:51
    Craig100
    0

    Ah, NOW I see :)

    Thanks for the clear explanation.

    I was totally aware and happy that the Grid stored it's content as JSON. What I was having trouble with was discovering a syntax that extracted and displayed it with Vorto. This particular content is from an RTE in a Grid in a Vorto wrapper. So it now makes sense that you extract the Vorto on it's own first then run it through the Partial. I was under the impression that bit "just happened".

    So, for anyone else coming by later, the final code that worked was:-

        @inherits Umbraco.Web.Mvc.UmbracoViewPage
        @using Our.Umbraco.Vorto.Extensions;
        @{
             Layout = "Master.cshtml";
        }    
        <div class="shadow">
            @{
                var gridObject = Model.GetVortoValue("bodyText");
            }
            @Html.Partial("Grid/Bootstrap3", gridObject)
        </div>
    

    Note: with UmbracoViewPage you don't need ".Content" hence "Model.GetVortoValue(......". With UmbracoTemplatePage it needs to be "Model.Content.GetVortoValue(......."

    Thanks again,

    --Craig

  • Mario Lopez 168 posts 952 karma points MVP 3x c-trib
    Oct 21, 2017 @ 11:12
    Mario Lopez
    0

    Great. Martin, did you solve your issue? You were the one who create the post! :)

Please Sign in or register to post replies

Write your reply to:

Draft