Copied to clipboard

Flag this post as spam?

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


  • Jeroen Oostwouder 100 posts 296 karma points
    Aug 11, 2016 @ 08:45
    Jeroen Oostwouder
    0

    Formvalidationmessages from Dictionary

    Hi there,

    I'm building a bi-lingual site, and I'm having trouble with the validation-messages.

    I used to do this in my model:

    [Required(ErrorMessage = "This field is required")]
    public string Name { get; set; }
    

    But now, I want to display an errormessage depending on the current culture.

    Is there a nice solution to this? I've tried replacing the errormessage with a variable or getting it directly from the umbraco dictionary, but that doesn't work. It needs to be a constant expression.

    Is there a way to bypass this? Can I make an errormessage which is a dictionary-alias? So I can display an error like:

    Umbraco.Field("#" + Errormessage)
    

    ?

    edit: So, I've noticed a can use:

    @Html.ValidationMessageFor(f => f.Name, umbracoHelper.Field("#CustomErrorMessage").ToString())
    

    To display a message per field.

    But is there still a way to make the display-name and errormessage in the model variable? It would be a lot less work :) Also, this method doesn't make a difference between a Required validation-error or a Emailaddress validation error :(

  • Yakov Lebski 539 posts 2101 karma points
    Aug 12, 2016 @ 16:56
    Yakov Lebski
    0

    You can use this package Umbraco Dictionary MetadataProvider, it's automatically bind model to dictionary values using naming convention.

Please Sign in or register to post replies

Write your reply to:

Draft