A thing like [DataType(DataType.number)] could be valuable for managing validation directly in the model. Look at the dotnet/corefx#4995 issue for best understanding why I ask for it.
Best regards.
dotnet/corefx#4995 is a PR that doesn't seem related to data annotations.
Did you mean to reference some other issue? And maybe you should explain why you think this would be useful in more detail.
Sorry @svick it is in the aspnet/Mvc repository.
_https://github.com/aspnet/Mvc/issues/4995#event-726593750_
As far as I know data annotations have useful features for validation in the model.
For example if you set "StringLength" and if the user type extra length an error message is generated.
But if you define a field with "int" and if the user type a value beginning with an alpha character, there is no error generated.
If your field is a "decimal", an error is generated.
So I think "int" have to react as decimal.
Best regards.
Data Annotations Triage: DataTypeAttribute does not implement validation, only some formatting functionality for specific types. Validation is implemented in attributes that derive from DataTypeAttribute such as EmailAddressAttribute, PhoneAttribute, etc.
What this issue seems to be asking for is for a new attribute that can be used to validate numeric inputs. That seems to be a reasonable idea and although we are not planning to work on it, we would consider taking a contribution.
This is not something we plan to implement. We might consider a community PR to implement such an attribute, but keep in mind it would be available on .NET Core only.
Sorry for my Newbie question but What is a community PR?
@MichelLaplane
Most helpful comment
dotnet/corefx#4995 is a PR that doesn't seem related to data annotations.
Did you mean to reference some other issue? And maybe you should explain why you think this would be useful in more detail.