Skip to content

Commit

Permalink
Merge branch 'dev' into issue/OCC-203
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahelsaig committed Apr 9, 2024
2 parents 1bc3431 + efd2b14 commit 20043ec
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Mvc.ModelBinding;
using OrchardCore.ContentManagement.Handlers;
using System.Linq;

namespace Lombiq.HelpfulLibraries.OrchardCore.Validation;

public static class ContentValidateResultExtensions
{
public static void AddValidationErrorsToModelState(this ContentValidateResult result, ModelStateDictionary modelState)
{
foreach (var error in result.Errors)
{
if (error.MemberNames.Any())
{
foreach (var memberName in error.MemberNames)
{
modelState.AddModelError(memberName, error.ErrorMessage);
}
}
else
{
modelState.AddModelError(string.Empty, error.ErrorMessage);
}
}
}
}

0 comments on commit 20043ec

Please sign in to comment.