Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Writing new post because I need more formatting than comments provide.</p> <p>Look at <strong>ValidationAttribute</strong> - base class of validation attributes.</p> <p>If validation error occured, error message will be created by method:</p> <pre><code>public virtual string FormatErrorMessage(string name) { return string.Format(CultureInfo.CurrentCulture, this.ErrorMessageString, new object[] { name }); } </code></pre> <p>Next look at <strong>ErrorMessageString</strong> property:</p> <pre><code>protected string ErrorMessageString { get { if (this._resourceModeAccessorIncomplete) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, DataAnnotationsResources.ValidationAttribute_NeedBothResourceTypeAndResourceName, new object[0])); } return this.ResourceAccessor(); } } </code></pre> <p>Property <strong>ResourceAccessor</strong> can be setted from:</p> <pre><code>ValidationAttribute..ctor(Func&lt;String&gt;) ValidationAttribute.set_ErrorMessage(String) : Void ValidationAttribute.SetResourceAccessorByPropertyLookup() : Void </code></pre> <p>First of it is exactly used by dervided classes to format messages, second - the case when we set error message trough <strong>ErrorMessage</strong> property, and third - when resource strings used. Depending on your situation, you may use <strong>ErrorMessageResourceName</strong>.</p> <p>Elsewhere let's look at derived constructors, for our example, Range Attribute:</p> <pre><code>private RangeAttribute() : base((Func&lt;string&gt;) (() =&gt; DataAnnotationsResources.RangeAttribute_ValidationError)) { } </code></pre> <p>Here <strong>RangeAttribute_ValidationError</strong> is loaded from resource:</p> <pre><code>internal static string RangeAttribute_ValidationError { get { return ResourceManager.GetString("RangeAttribute_ValidationError", resourceCulture); } } </code></pre> <p>So you can create resource file for different tan default culture and overwrite messages there, like this:</p> <p><a href="http://www.codeproject.com/KB/aspnet/SatelliteAssemblies.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/aspnet/SatelliteAssemblies.aspx</a></p> <p><a href="http://msdn.microsoft.com/en-us/library/aa645513(VS.71).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/aa645513(VS.71).aspx</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload