Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • David Armitage 489 posts 2048 karma points
    Feb 28, 2022 @ 12:27
    David Armitage
    0

    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?

    Thanks in advance.

    David

  • Philip Hayton 84 posts 410 karma points
    Mar 16, 2022 @ 16:09
    Philip Hayton
    0

    Don't suppose you found a solution to this did you?

  • Philip Hayton 84 posts 410 karma points
    Mar 25, 2022 @ 15:15
    Philip Hayton
    0

    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 🙏🏻

Please Sign in or register to post replies

Write your reply to:

Draft