You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
857 B
28 lines
857 B
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
|
|
|
namespace Infrastructure.Extensions
|
|
{
|
|
public static class ModelStateDictionaryExtensions
|
|
{
|
|
public static void AddModelError(this ModelStateDictionary modelState, IList<ValidationResult> validationResults)
|
|
{
|
|
foreach (var item in validationResults)
|
|
{
|
|
if (item.MemberNames.Any())
|
|
{
|
|
foreach (var key in item.MemberNames)
|
|
{
|
|
modelState.AddModelError(key, item.ErrorMessage);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
modelState.AddModelError("", item.ErrorMessage);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |