From a500812e88ac5a8acdd9732963e6fae95c0a73e6 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 7 May 2020 22:41:37 -0400 Subject: update web project to .NET Core 3.1 --- src/SMAPI.Web/Framework/Extensions.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/SMAPI.Web/Framework') diff --git a/src/SMAPI.Web/Framework/Extensions.cs b/src/SMAPI.Web/Framework/Extensions.cs index e0da1424..96463233 100644 --- a/src/SMAPI.Web/Framework/Extensions.cs +++ b/src/SMAPI.Web/Framework/Extensions.cs @@ -1,8 +1,12 @@ using System; using JetBrains.Annotations; +using Microsoft.AspNetCore.Html; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Razor; +using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Routing; +using Newtonsoft.Json; namespace StardewModdingAPI.Web.Framework { @@ -34,5 +38,16 @@ namespace StardewModdingAPI.Web.Framework } return url; } + + /// Get a serialized JSON representation of the value. + /// The page to extend. + /// The value to serialize. + /// The serialized JSON. + /// This bypasses unnecessary validation (e.g. not allowing null values) in . + public static IHtmlContent ForJson(this RazorPageBase page, object value) + { + string json = JsonConvert.SerializeObject(value); + return new HtmlString(json); + } } } -- cgit