dotnet / dotnet/aspnetcore

Length client side validation of HTML Select isn't working properly

Open
#41,152 1 comment 0 reactions 0 assignees View on GitHub
area-mvc investigate
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

Data Annotations StringLength for client side validation of HTML Select isn't working properly. After some testing, it looks like the client side validation thinks the length of an HTML select value is always 1 (assuming something is actually selected). All server side validation is working fine, but the client is stopping it.

I realize this an odd use case. This only comes up because I want the property to have an exact length and I use it for HTML Selects on the front-end. So I decorated it with `[StringLength(9, MinimumLength = 9)]` and the client side validation stops it thinking it has a length of 1.

### Expected Behavior

I expect the client side validation to properly evaluate the length of a value even though it is in an HTML Select.

### Steps To Reproduce

The test project can be found at [https://github.com/TheWayTC/ValidationTesting](https://github.com/TheWayTC/ValidationTesting).

Let me know if you need anything else.

### Exceptions (if any)

_No response_

### .NET Version

6.0.201

### Anything else?

_No response_

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.