Skip to content

Commit

Permalink
Copy UpdateModelExtensions from OCC.
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahelsaig committed Nov 9, 2023
1 parent b380135 commit d651eb4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Lombiq.HelpfulLibraries.OrchardCore/Mvc/UpdateModelExtensions.cs
Original file line number Diff line number Diff line change
@@ -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<ModelError> GetModelErrors(this IUpdateModel updateModel) =>
updateModel
.ModelState
.Values
.SelectMany(entry => entry.Errors)
.Where(error => !string.IsNullOrWhiteSpace(error.ErrorMessage));

public static IEnumerable<string> GetModelErrorMessages(this IUpdateModel updateModel) =>
updateModel.GetModelErrors().Select(error => error.ErrorMessage);
}

0 comments on commit d651eb4

Please sign in to comment.