Copied to clipboard

Flag this post as spam?

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


  • Sebastian Dammark 547 posts 1287 karma points
    Dec 28, 2019 @ 15:45
    Sebastian Dammark
    0

    Render Grid in JSON gives me a weird output

    I'm trying to generate a JSON output through a view, but when I do I get this weird output in the content property, a shitload of empty JSON. enter image description here

    If I do the same through a regular view in a textarea I get this, which is what I expect. enter image description here

    When I output the Grid in JSON I do like this

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @{
      Layout = null;
      IPublishedContent site = Model;
    
      var content = (site.HasValue("GridContent")) ? site.Value("GridContent") : null;
    
      var output = new {
        id = site.Id,
        order = site.SortOrder,
        language = site.GetCultureFromDomains(),
        type = site.ContentType.Alias,
        content = content,
      };
    
      string json = Json.Encode(output);
      Response.ContentType = "application/json";
    } @Html.Raw(json)
    

    And in the textarea template I do like this

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @{
      Layout = null;
      var content = (Model.HasValue("GridContent")) ? Model.Value("GridContent") : null;
      <textarea>@content</textarea>
    }
    

    Any ideas on why I get this crappy output when I try in the JSON template ?

  • Graham Davis 104 posts 359 karma points
    Dec 29, 2019 @ 05:03
    Graham Davis
    0

    The browser is trying to format the output as it would HTML. Try using the "code" tag so it will know to ignore it.

    https://www.w3schools.com/TAGs/tag_code.asp

  • Sebastian Dammark 547 posts 1287 karma points
    Dec 29, 2019 @ 06:44
    Sebastian Dammark
    0

    Nope, that's not the case.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies