diff --git a/Lombiq.HelpfulLibraries.OrchardCore/Mvc/UpdateModelExtensions.cs b/Lombiq.HelpfulLibraries.OrchardCore/Mvc/UpdateModelExtensions.cs new file mode 100644 index 00000000..7a9cfe6a --- /dev/null +++ b/Lombiq.HelpfulLibraries.OrchardCore/Mvc/UpdateModelExtensions.cs @@ -0,0 +1,18 @@ +using Microsoft.AspNetCore.Mvc.ModelBinding; +using System.Collections.Generic; +using System.Linq; + +namespace OrchardCore.DisplayManagement.ModelBinding; + +public static class UpdateModelExtensions +{ + public static IEnumerable GetModelErrors(this IUpdateModel updateModel) => + updateModel + .ModelState + .Values + .SelectMany(entry => entry.Errors) + .Where(error => !string.IsNullOrWhiteSpace(error.ErrorMessage)); + + public static IEnumerable GetModelErrorMessages(this IUpdateModel updateModel) => + updateModel.GetModelErrors().Select(error => error.ErrorMessage); +}