Currently there is a bug in ASP.NET MVC 5 which is not taking care of System.ComponentModel.DataAnnotations.CompareAttribute.ErrorMessage. When I dive into source, I found that CompareAttributeWrapper.FormatErrorMessage is not using attribute.ErrorMessage,
```
private sealed class CompareAttributeWrapper : DataAnnotationsCompareAttribute
{
private readonly string _otherPropertyDisplayName;
public CompareAttributeWrapper(DataAnnotationsCompareAttribute attribute, ModelMetadata metadata)
: base(attribute.OtherProperty)
{
_otherPropertyDisplayName = attribute.OtherPropertyDisplayName;
if (_otherPropertyDisplayName == null && metadata.ContainerType != null)
{
_otherPropertyDisplayName = ModelMetadataProviders.Current.GetMetadataForProperty(() => metadata.Model, metadata.ContainerType, attribute.OtherProperty).GetDisplayName();
}
}
public override string FormatErrorMessage(string name)
{
return String.Format(CultureInfo.CurrentCulture, ErrorMessageString, name, _otherPropertyDisplayName ?? OtherProperty);
}
}
```
You can easily reproduce it using,
```
[Compare("Password", ErrorMessage = "The password & confirmation password are not matched.")]
```
In this case the ErrorMessage will never used. The quick fix will be to use obselete System.Web.Mvc.CompareAttribute,
```
[System.Web.Mvc.Compare("Password", ErrorMessage = "The password & confirmation password are not matched.")]
```
Comments: fixed by: https://aspnetwebstack.codeplex.com/workitem/1401
```
private sealed class CompareAttributeWrapper : DataAnnotationsCompareAttribute
{
private readonly string _otherPropertyDisplayName;
public CompareAttributeWrapper(DataAnnotationsCompareAttribute attribute, ModelMetadata metadata)
: base(attribute.OtherProperty)
{
_otherPropertyDisplayName = attribute.OtherPropertyDisplayName;
if (_otherPropertyDisplayName == null && metadata.ContainerType != null)
{
_otherPropertyDisplayName = ModelMetadataProviders.Current.GetMetadataForProperty(() => metadata.Model, metadata.ContainerType, attribute.OtherProperty).GetDisplayName();
}
}
public override string FormatErrorMessage(string name)
{
return String.Format(CultureInfo.CurrentCulture, ErrorMessageString, name, _otherPropertyDisplayName ?? OtherProperty);
}
}
```
You can easily reproduce it using,
```
[Compare("Password", ErrorMessage = "The password & confirmation password are not matched.")]
```
In this case the ErrorMessage will never used. The quick fix will be to use obselete System.Web.Mvc.CompareAttribute,
```
[System.Web.Mvc.Compare("Password", ErrorMessage = "The password & confirmation password are not matched.")]
```
Comments: fixed by: https://aspnetwebstack.codeplex.com/workitem/1401