* Include DisplayName in errorMessage
This commit is contained in:
parent
c5346f7bf9
commit
d22d6793ba
|
|
@ -52,15 +52,17 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation
|
|||
throw new ArgumentNullException(nameof(modelMetadata));
|
||||
}
|
||||
|
||||
var displayName = modelMetadata.GetDisplayName();
|
||||
|
||||
if (_stringLocalizer != null &&
|
||||
!string.IsNullOrEmpty(Attribute.ErrorMessage) &&
|
||||
string.IsNullOrEmpty(Attribute.ErrorMessageResourceName) &&
|
||||
Attribute.ErrorMessageResourceType == null)
|
||||
{
|
||||
return _stringLocalizer[Attribute.ErrorMessage];
|
||||
return _stringLocalizer[Attribute.ErrorMessage, displayName];
|
||||
}
|
||||
|
||||
return Attribute.FormatErrorMessage(modelMetadata.GetDisplayName());
|
||||
return Attribute.FormatErrorMessage(displayName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation
|
|||
string.IsNullOrEmpty(Attribute.ErrorMessageResourceName) &&
|
||||
Attribute.ErrorMessageResourceType == null)
|
||||
{
|
||||
errorMessage = _stringLocalizer[Attribute.ErrorMessage];
|
||||
var displayName = validationContext.Metadata.GetDisplayName();
|
||||
errorMessage = _stringLocalizer[Attribute.ErrorMessage, displayName];
|
||||
}
|
||||
|
||||
var validationResult = new ModelValidationResult(errorMemberName, errorMessage ?? result.ErrorMessage);
|
||||
|
|
|
|||
|
|
@ -268,7 +268,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation
|
|||
|
||||
var localizedString = new LocalizedString("Length", "Longueur est invalide");
|
||||
var stringLocalizer = new Mock<IStringLocalizer>();
|
||||
stringLocalizer.Setup(s => s["Length"]).Returns(localizedString);
|
||||
stringLocalizer.Setup(s => s["Length", It.IsAny<object[]>()]).Returns(localizedString);
|
||||
|
||||
var validator = new DataAnnotationsModelValidator(attribute.Object, stringLocalizer.Object);
|
||||
var validationContext = new ModelValidationContext()
|
||||
|
|
|
|||
|
|
@ -77,7 +77,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation
|
|||
attribute.ErrorMessage = errorKey;
|
||||
var localizedString = new LocalizedString(errorKey, "Longueur est invalide");
|
||||
var stringLocalizer = new Mock<IStringLocalizer>();
|
||||
stringLocalizer.Setup(s => s[errorKey]).Returns(localizedString);
|
||||
stringLocalizer.Setup(s => s[errorKey, It.IsAny<object[]>()]).Returns(localizedString);
|
||||
|
||||
var adapter = new MaxLengthAttributeAdapter(attribute, stringLocalizer.Object);
|
||||
|
||||
var actionContext = new ActionContext();
|
||||
|
|
@ -94,4 +95,4 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation
|
|||
Assert.Equal("Longueur est invalide", rule.ErrorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue