dotnet / dotnet/aspnetcore

AllowedValuesAttribute mesage doesn't get localize because its missing its AttributeAdapter

Open
#53,632 0 comments 2 reactions 0 assignees View on GitHub
area-mvc
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.