Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>EDIT:</strong> I found the answer here: <a href="http://forums.silverlight.net/forums/p/149264/377212.aspx" rel="nofollow noreferrer">http://forums.silverlight.net/forums/p/149264/377212.aspx</a></p> <p>Before validating, you need to manually register the metadata class:</p> <pre><code>TypeDescriptor.AddProviderTransparent( new AssociatedMetadataTypeTypeDescriptionProvider(typeof(Person), typeof(PersonMetadata)), typeof(Person)); List&lt;ValidationResult&gt; res = new List&lt;ValidationResult&gt;(); bool valid = Validator.TryValidateObject(p, new ValidationContext(p, null, null), res, true); </code></pre> <p><em>(Original answer follows)</em></p> <p>The problem isn't specifically with your partial class, it's that Validator.TryValidateObject doesn't seem to recognize the MetaDataType attribute. I have the same problem - the built-in validation in MVC 2 recognizes the metadata class, but TryValidateObject doesn't.</p> <p>See these: <a href="https://stackoverflow.com/questions/2050161/validating-dataannotations-with-validator-class">Validating DataAnnotations with Validator class</a> <a href="https://stackoverflow.com/questions/2422031/validation-does-not-work-when-i-use-validator-tryvalidateobject">Validation does not work when I use Validator.TryValidateObject</a></p> <p>As a side note, I don't know if it's necessary, but all examples I've seen for metadata classes employ the default get/set on each property:</p> <pre><code>[Required(AllowEmptyStrings=false, ErrorMessage="Name required entry")] [StringLength(3)] public string Name { get; set; } </code></pre>
 

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