1

I have a JSON file that has some simple fields and content. I want to make a 2sxc app that simply lists out the content of the JSON file using C# Razor. (Ultimately this json file will be hosted elsewhere).

Ideally, the content will be rendered as simple HTML in the page that I can see when I click view source in the browser so I know it's SEO friendly.

Is this possible? What kind of code would I need to do this?

1 Answers1

4

I was able to figure it out using this example: https://2sxc.org/dnn-tutorials/en/razor/json/home

So my code looked something like this:

@inherits ToSic.Sxc.Dnn.RazorComponent
@inherits Custom.Hybrid.Razor12

@{
  var someJson = System.IO.File.ReadAllText(App.PhysicalPath + "/json/UseCases.json");
  var thing = AsDynamic(someJson);
}



@foreach(var useCase in thing.UseCases) {
<a href="@("/use-case/" + @useCase.URLPart)">@useCase.URLPart</a>
  <h3>Name: @useCase.Name</h3>

    <h4>@useCase.Domain</h4>

  <p>@useCase.ShortDescription</p>
  
 
  
  @Html.Raw(useCase.Highlights)
  
  }
  • awesome, glad the tutorials are being used ;). Best mark this as the answer, so people see the question is answered. – iJungleBoy Oct 14 '21 at 06:04