Copied to clipboard

Flag this post as spam?

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


  • Thomas 1 post 71 karma points
    23 days ago
    Thomas
    0

    Desperate: Holding a lesson in Umbraco tomorrow - can't get any REST API/headless options to work...

    So I am a bit to green at Umbraco 8 - but is still holding a course in WCMS:es with Umbraco as an important player...

    Tomorrow my lesson planing is "go 'headless'" but I'm stuck in a rut. "Headless Umbraco 8" is not here yet, looked at the Headrest-library, but it looked complicated to me.

    Wanted to try a simple solution like this one: https://gist.github.com/EdCharbeneau/702a4c2d702d30f371bd

    but can't get it to work in Umbraco 8.2... Any breaking changes/simple rewrite of this little gist I could use?

    Any help much appreciated!

    :(

  • Alex Skrypnyk 5365 posts 19802 karma points MVP 3x admin c-trib
    6 days ago
    Alex Skrypnyk
    0

    Hi Thomas

    Maybe this will work for you:

    @using Newtonsoft.Json;
    @using System.Dynamic;
    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @{
        Layout = null;
        Response.ContentType = "application/json";
        dynamic exObj = new ExpandoObject();
        var dictionary = exObj as IDictionary<string, object>;
    
        Model.Properties.ToList().ForEach(p => dictionary[p.Alias] = p.GetValue());
    }
    @Html.Raw(JsonConvert.SerializeObject(exObj))
    
  • Alex Skrypnyk 5365 posts 19802 karma points MVP 3x admin c-trib
    4 hours ago
    Alex Skrypnyk
    0

    Let me know if it helps or no

Please Sign in or register to post replies

Write your reply to:

Draft