From ce2be53cc917b6973d0a31d8901908ca6ff847ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ra=20El-Saig?= Date: Fri, 9 Aug 2024 15:04:25 +0200 Subject: [PATCH] Add AddModelError. --- .../Contents/BuildEditorContextExtensions.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Lombiq.HelpfulLibraries.OrchardCore/Contents/BuildEditorContextExtensions.cs b/Lombiq.HelpfulLibraries.OrchardCore/Contents/BuildEditorContextExtensions.cs index c9d05eff..d88de992 100644 --- a/Lombiq.HelpfulLibraries.OrchardCore/Contents/BuildEditorContextExtensions.cs +++ b/Lombiq.HelpfulLibraries.OrchardCore/Contents/BuildEditorContextExtensions.cs @@ -1,6 +1,8 @@ #nullable enable +using Microsoft.Extensions.Localization; using OrchardCore.DisplayManagement.Entities; +using OrchardCore.DisplayManagement.ModelBinding; using System; using System.Threading.Tasks; @@ -71,4 +73,11 @@ public static async Task CreateModelAsync(this BuildEdit await context.Updater.TryUpdateModelAsync(viewModel, prefix); return viewModel; } + + /// + /// Adds an error message to the .. The + /// is , because it's user-facing data. + /// + public static void AddModelError(this BuildEditorContext context, string key, LocalizedString message) => + context.Updater.ModelState.AddModelError(key, message); }