AllowedValuesAttribute mesage doesn't get localize because its missing its AttributeAdapter
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 276
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
if AllowedValues be use like below
[AllowedValues("test", ErrorMessage = "AllowedValuesAttribute_Invalid")]
public string Test{ get; set; }
its dosent get localize unlike other ValidationAttribute
for example below code will localize
[Required(ErrorMessage = "RequiredAttribute_ValidationError")]
public Guid Code { get; set; }
localize setting that i useing is sometihing like :
services.AddControllers()
.AddDataAnnotationsLocalization(options =>
{
options.DataAnnotationLocalizerProvider = (_, factory) =>
factory.Create(typeof(SharedResource));
})
### Expected Behavior
localize ErrorMessage like other ValidationAttribute
for example below code will localize
[Required(ErrorMessage = "RequiredAttribute_ValidationError")]
public Guid Code { get; set; }
### Steps To Reproduce
1- config DataAnnotationsLocalization with something like below
services.AddControllers()
.AddDataAnnotationsLocalization(options =>
{
options.DataAnnotationLocalizerProvider = (_, factory) =>
factory.Create(typeof(SharedResource));
})
2- use AllowedValues to mvc controller input model with ErrorMessage prop fill with your localize key
[AllowedValues("test", ErrorMessage = "AllowedValuesAttribute_Invalid")]
public string Test{ get; set; }
### Exceptions (if any)
_No response_
### .NET Version
8.0.101
### Anything else?
i thing its because of missing its AttributeAdapter and not being set on
https://github.com/dotnet/aspnetcore/blob/de12f70f8d536a72bd8c6a2add8f6c8ad8f344af/src/Mvc/Mvc.DataAnnotations/src/ValidationAttributeAdapterProvider.cs#L20
Contributor guide
Assessment
This issue has not been assessed yet.