Created
October 6, 2015 10:22
-
-
Save pparadis/d9a091d339331904d4bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foreach (ModelError error in modelState.Errors.Where(err => String.IsNullOrEmpty(err.ErrorMessage) && err.Exception != null).ToList()) | |
{ | |
for (Exception exception = error.Exception; exception != null; exception = exception.InnerException) | |
{ | |
// We only consider "known" type of exception and do not make too aggressive changes here | |
if (exception is FormatException || exception is OverflowException) | |
{ | |
string displayName = propertyMetadata.GetDisplayName(); | |
string errorMessageTemplate = GetValueInvalidResource(controllerContext); | |
string errorMessage = String.Format(CultureInfo.CurrentCulture, errorMessageTemplate, modelState.Value.AttemptedValue, displayName); | |
modelState.Errors.Remove(error); | |
modelState.Errors.Add(errorMessage); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment