public static string GetModelErrorMessageOrDefault(ModelError modelError) { Debug.Assert(modelError != null); if (!string.IsNullOrEmpty(modelError.ErrorMessage)) { return modelError.ErrorMessage; } // Default in the ValidationSummary case is no error message. return string.Empty; }
public static string GetModelErrorMessageOrDefault( ModelError modelError, ModelStateEntry containingEntry, ModelExplorer modelExplorer) { Debug.Assert(modelError != null); Debug.Assert(containingEntry != null); Debug.Assert(modelExplorer != null); if (!string.IsNullOrEmpty(modelError.ErrorMessage)) { return modelError.ErrorMessage; } // Default in the ValidationMessage case is a fallback error message. var attemptedValue = containingEntry.AttemptedValue ?? "null"; return modelExplorer.Metadata.ModelBindingMessageProvider.ValueIsInvalidAccessor(attemptedValue); }
private static void AssertRequiredError(string key, ModelError error) { // Mono issue - https://github.com/aspnet/External/issues/19 Assert.Equal(PlatformNormalizer.NormalizeContent( string.Format("The {0} field is required.", key)), error.ErrorMessage); Assert.Null(error.Exception); }