Umbraco 9 - Dictionary Labels in DataAnnotation Attributes for form labels and validation messages
Hi All,
Has anyone figured out how to use dictionary labels in basic form models for DataAnnotation error messages etc.
Eg.
[DisplayName("First Name")]
[Required(ErrorMessage = "Please fill out the required field")]
[StringLength(50, ErrorMessage = "Please reduce to a maximum of 50 characters")]
public string FirstName { get; set; }
So something on the lines of this that obviously doesn't work.
[DisplayName("First Name")]
[Required(ErrorMessage = _umbracoHelper.GetDictionaryValue("First Name"))]
[StringLength(50, ErrorMessage = _umbracoHelper.GetDictionaryValue("Please reduce to a maximum of 50 characters"))]
public string FirstName { get; set; }
Any help would be much appreciated.
Its always a pain to get attributes working like this. I assumed Unmbraco may have found a good way of handling this now?
It is not help, it provides you own annotation attributes instead of original.
For umbraco 7 i had spent couple of hours to make it works with original .net data annotation.
Idea was to register own annotation provider. Strange that umbraco doesn't contains that from start. but.
Umbraco 9 - Dictionary Labels in DataAnnotation Attributes for form labels and validation messages
Hi All,
Has anyone figured out how to use dictionary labels in basic form models for DataAnnotation error messages etc.
Eg.
So something on the lines of this that obviously doesn't work.
Any help would be much appreciated. Its always a pain to get attributes working like this. I assumed Unmbraco may have found a good way of handling this now?
Thanks in advance.
David
Don't suppose you found a solution to this did you?
Just want to update this thread with the following package which solved this problem for me.
https://our.umbraco.com/packages/developer-tools/umbraco-validation-attributes/
Thank you so much to Martino 🙏🏻
It is not help, it provides you own annotation attributes instead of original. For umbraco 7 i had spent couple of hours to make it works with original .net data annotation. Idea was to register own annotation provider. Strange that umbraco doesn't contains that from start. but.
Following provider could be used from .net core version:
Class has to be registered instead of orginial service as singletone: builder.Register(x => new UmbracoModelMetadataProvider()).AsSelf().As
We developed dictionary data anotation for umbraco 10+ - you can try to use it https://www.nuget.org/packages/Dyfort.Umbraco.DictionaryMetadataProvider/1.0.0-beta1
is working on a reply...