Copied to clipboard

Flag this post as spam?

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


  • Abhishek Gupta 2 posts 71 karma points
    Apr 26, 2019 @ 07:24
    Abhishek Gupta
    0

    How to get Json from umbraco content

    Hi Team,

    Can you please suggest the ways of getting the Json instead of front end layout (preview) when we click on any content?

  • Dave de Moel 122 posts 574 karma points c-trib
    Apr 26, 2019 @ 08:06
    Dave de Moel
    0

    Can you elaborate a bit more about what you want to accomplish. Normally I would suggest using an API controller if you want json data, which can format it automatically if you set the default formatter to a json formatter:

     public class ApiConfigurationComponent : IComponent
        {
            public void Initialize()
            {
                GlobalConfiguration.Configuration.Formatters.Clear();
                GlobalConfiguration.Configuration.Formatters.Add(new JsonMediaTypeFormatter
                {
                    SerializerSettings = new JsonSerializerSettings
                    {
                        ContractResolver = new CamelCasePropertyNamesContractResolver()
                    }
                }); 
            }
    
  • Bryna 74 posts 260 karma points
    Apr 26, 2019 @ 21:22
    Bryna
    0

    Perhaps a surface controller(https://our.umbraco.com/documentation/reference/routing/surface-controllers)? Instead of returning an ActionResult, you could return a JSONResult. Also assuming that the data is for public consumption.

Please Sign in or register to post replies

Write your reply to:

Draft