Hi @Brian Ashcraft
Based on the JSON string, I create a Razor page with the following code, you can refer to them:
Index.cshtml: Display the data via the page model.
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
@if(Model.Videolist !=null)
{
foreach(var item in Model.Videolist.items)
{
<div>
<span>@item.snippet.title</span><br/>
<span>@item.snippet.description</span><br />
<span>@item.snippet.thumbnails.medium.url</span><br />
<span>@item.snippet.thumbnails.medium.width</span><br />
<span>@item.snippet.thumbnails.medium.height</span><br />
</div>
<hr />
}
}
@section Scripts {
@{
await Html.RenderPartialAsync("_ValidationScriptsPartial");
}
}
Index.cshtml.cs
using Core7RazorSample.Data;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Newtonsoft.Json;
namespace Core7RazorSample.Pages
{
public class IndexModel : PageModel
{
private readonly ILogger<IndexModel> _logger;
public IndexModel(ILogger<IndexModel> logger)
{
_logger = logger;
}
[BindProperty]
public videoList? Videolist { get; set; }
public void OnGet()
{
//call api and get json string.
string jsonString = "{\"items\":[{\"snippet\":{\"title\":\"SampleVideo1\",\"description\":\"LighthouseandHills\",\"thumbnails\":{\"medium\":{\"url\":\"https://i.ytimg.com/vi/QMQMxIM3gkU/mqdefault.jpg\",\"width\":320,\"height\":180}}}},{\"snippet\":{\"title\":\"SampleVideo2\",\"description\":\"WateringFlowers\",\"thumbnails\":{\"medium\":{\"url\":\"https://i.ytimg.com/vi/ZlR1JCBrr4g/mqdefault.jpg\",\"width\":320,\"height\":180}}}},{\"snippet\":{\"title\":\"SampleVideo3\",\"description\":\"MMOVideo\",\"thumbnails\":{\"medium\":{\"url\":\"https://i.ytimg.com/vi/_Fh4t4QuAfE/mqdefault.jpg\",\"width\":320,\"height\":180}}}}]}";
if (jsonString != null)
{
Videolist = JsonConvert.DeserializeObject<videoList>(jsonString);
}
}
}
}
The result as below:
More detail information, refer to Model Binding in ASP.NET Core and Introduction to Razor Pages in ASP.NET Core.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion