22 lines
819 B
C#
22 lines
819 B
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace EnVisage.Code.Extensions
|
|
{
|
|
public static class ValidationExtensions
|
|
{
|
|
public static List<EnVisage.Code.Validation.FieldValidationError> GetModelStateErrors(this System.Web.Mvc.ModelStateDictionary modelState)
|
|
{
|
|
if (null == modelState || modelState.IsValid)
|
|
return null;
|
|
var errorModel = (from x in modelState.Keys
|
|
where modelState[x].Errors.Count > 0
|
|
select new EnVisage.Code.Validation.FieldValidationError
|
|
{
|
|
FieldName = x,
|
|
ErrorMessages = modelState[x].Errors.Select(y => y.ErrorMessage).ToList()
|
|
}).ToList();
|
|
return errorModel;
|
|
}
|
|
}
|
|
} |