fix #3414 : RegularExpressionAttribute generates wrong data-val-regex message

This commit is contained in:
Kirthi Krishnamraju 2015-11-03 15:44:30 -08:00
parent 380a93d370
commit 454ff9f52a
3 changed files with 7 additions and 8 deletions

View File

@ -52,16 +52,15 @@ 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)
!string.IsNullOrEmpty(Attribute.ErrorMessage) &&
string.IsNullOrEmpty(Attribute.ErrorMessageResourceName) &&
Attribute.ErrorMessageResourceType == null)
{
return _stringLocalizer[displayName];
return _stringLocalizer[Attribute.ErrorMessage];
}
return Attribute.FormatErrorMessage(displayName);
return Attribute.FormatErrorMessage(modelMetadata.GetDisplayName());
}
}
}

View File

@ -7,7 +7,7 @@ namespace LocalizationWebSite.Models
{
public class User
{
[MinLength(4, ErrorMessage = "Name")]
[MinLength(4, ErrorMessage = "NameError")]
public string Name { get; set; }
public Product Product { get; set; }

View File

@ -117,7 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Name" xml:space="preserve">
<data name="NameError" xml:space="preserve">
<value>Nom non valide. Longueur minimale de nom est 4</value>
</data>
</root>